-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Service Bus Sessions Example #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Threading.Tasks; | ||
using MassTransit; | ||
using Microsoft.Extensions.Logging; | ||
using Sample.Contracts; | ||
|
||
namespace Sample.Worker.Consumers | ||
{ | ||
public class OrderShippedConsumer : | ||
IConsumer<OrderShipped> | ||
{ | ||
private readonly ILogger<OrderShippedConsumer> _logger; | ||
|
||
public OrderShippedConsumer(ILogger<OrderShippedConsumer> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public Task Consume(ConsumeContext<OrderShipped> context) | ||
{ | ||
_logger.LogInformation("Order Shipped with OrderId: {OrderId}. SessionId {SessionId}.", | ||
context.Message.OrderId, context.SessionId()); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
using System; | ||
|
||
namespace Sample.Worker | ||
{ | ||
using System.Threading.Tasks; | ||
|
@@ -29,6 +31,10 @@ public static IHostBuilder CreateHostBuilder(string[] args) | |
|
||
x.AddConsumer<SubmitOrderConsumer>(); | ||
x.AddConsumer<OrderSubmittedConsumer>(); | ||
x.AddConsumer<OrderShippedConsumer>(e => | ||
{ | ||
e.UseTimeout(c => c.Timeout = TimeSpan.FromSeconds(10)); | ||
}); | ||
|
||
x.AddSagaStateMachine<OrderShipmentStateMachine, OrderShipmentState, OrderShipmentSagaDefinition>() | ||
.MessageSessionRepository(); | ||
|
@@ -48,6 +54,19 @@ public static IHostBuilder CreateHostBuilder(string[] args) | |
e.ConfigureConsumer<OrderSubmittedConsumer>(context); | ||
}); | ||
|
||
cfg.Publish<OrderShippedBase>(configurator => configurator.Exclude = true); | ||
cfg.SubscriptionEndpoint<OrderShipped>("order-shipped-consumer", e => | ||
{ | ||
e.ConfigureConsumeTopology = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also unnecessary noise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is needed otherwise it will make unwanted service bus topics for interfaces and inheritance You have a discussion recommending this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm referring to the ConfigureConsumeTopology = false |
||
e.AutoStart = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary, noise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True |
||
e.AutoDeleteOnIdle = TimeSpan.FromDays(30); | ||
e.MaxDeliveryCount = 2; | ||
e.RequiresSession = true; | ||
e.MaxConcurrentCalls = 8; //like AZ Function default. 8 Concurrent consumers handling 1 ServiceBus Session | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, no,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ConcurrentMessageLimit didn't respect sessions. I have a test / sample proving this. I will add here tomorrow |
||
e.PrefetchCount = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really a valid value you should specify. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you are right, it isn't needed AZ funcs prefect too with peek, as long as the prefect does not ack and respects sessions. |
||
e.ConfigureConsumer<OrderShippedConsumer>(context); | ||
}); | ||
|
||
cfg.ConfigureEndpoints(context); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really used and probably just confuses people.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't it fail the SB and not ack of the message handling takes to long?
Ie it will ensure failed process are put to failed?
But you are right it can be found easy enough, not needed here