Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Wolverine.Runtime;
using Wolverine.Tracking;
using Xunit;

namespace CoreTests.Acceptance;

public class publishing_ISendMyself_messages : IntegrationContext
{
public publishing_ISendMyself_messages(DefaultApp @default) : base(@default)
{
}

[Fact]
public async Task assert_can_not_send_with_isendmyself()
{
var selfSender = new SelfSender(Guid.NewGuid());
var tracked = await Host.SendMessageAndWaitAsync(selfSender);
tracked.Executed.SingleMessage<Cascaded>().Id.ShouldBe(selfSender.Id);
}

[Fact]
public async Task assert_can_not_publish_with_isendmyself()
{
var selfSender = new SelfSender(Guid.NewGuid());
var tracked = await Host.ExecuteAndWaitValueTaskAsync(c => c.PublishAsync(selfSender));
tracked.Executed.SingleMessage<Cascaded>().Id.ShouldBe(selfSender.Id);
}
}
21 changes: 20 additions & 1 deletion src/Wolverine/Runtime/MessageBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Wolverine.Runtime;

public class MessageBus : IMessageBus
public class MessageBus : IMessageBus, IMessageContext
{
public static MessageBus Build(IWolverineRuntime runtime, string correlationId) =>
new MessageBus(runtime, correlationId);
Expand Down Expand Up @@ -42,6 +42,11 @@ private void assertNotMediatorOnly()
}

public string? CorrelationId { get; set; }
public Envelope? Envelope { get; protected set; }
public virtual ValueTask RespondToSenderAsync(object response)
{
throw new NotSupportedException("Not supported from MessageBus, only within message handlers executing against MessageContext");
}

public IWolverineRuntime Runtime { get; }
public IMessageStore Storage { get; protected set; }
Expand Down Expand Up @@ -146,6 +151,13 @@ public ValueTask SendAsync<T>(T message, DeliveryOptions? options = null)
{
throw new ArgumentNullException(nameof(message));
}

// Check for both so you don't get an infinite loop
// from TimeoutMessage
if (options == null && message is ISendMyself m)
{
return m.ApplyAsync(this);
}

Runtime.AssertHasStarted();
assertNotMediatorOnly();
Expand All @@ -164,6 +176,13 @@ public ValueTask PublishAsync<T>(T message, DeliveryOptions? options = null)
throw new ArgumentNullException(nameof(message));
}

// Check for both so you don't get an infinite loop
// from TimeoutMessage
if (options == null && message is ISendMyself m)
{
return m.ApplyAsync(this);
}

Runtime.AssertHasStarted();
assertNotMediatorOnly();

Expand Down
4 changes: 1 addition & 3 deletions src/Wolverine/Runtime/MessageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public ValueTask RollbackAsync()
/// <param name="context"></param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
/// <returns></returns>
public ValueTask RespondToSenderAsync(object response)
public override ValueTask RespondToSenderAsync(object response)
{
if (Envelope == null)
{
Expand All @@ -312,8 +312,6 @@ public ValueTask RespondToSenderAsync(object response)
return EndpointFor(Envelope.ReplyUri).SendAsync(response);
}

public Envelope? Envelope { get; protected set; }

internal async Task CopyToAsync(IEnvelopeTransaction other)
{
await other.PersistOutgoingAsync(_outstanding.ToArray());
Expand Down
Loading