我试图在Azure WorkerRole上运行Autofac和Azure Service Bus时使用Masstransit,一切正常,直到达到MaxConcurrentCalls,而不是消耗掉所有已发布的事件。
这是我的EntryPoint
ndf = ndf.sort_index(level=1,ascending=False)
和SAGA
public class WorkerRole : RoleEntryPoint
{
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private readonly ManualResetEvent runCompleteEvent = new ManualResetEvent(false);
private IBusControl _bus;
private IContainer _container;
public override void Run()
{
Trace.TraceInformation("POC is running");
try
{
this.RunAsync(this.cancellationTokenSource.Token).Wait();
}
finally
{
this.runCompleteEvent.Set();
}
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
string connectionString = CloudConfigurationManager.GetSetting("AzureServiceBusConnectionString");
string queue = CloudConfigurationManager.GetSetting("AzureServiceBusQueue");
bool result = base.OnStart();
if (result)
{
XmlConfigurator.Configure();
var builder = new ContainerBuilder();
builder.RegisterConsumers(Assembly.GetExecutingAssembly());
builder.RegisterType<InMemorySagaRepository<PocSaga>>().As<ISagaRepository<PocSaga>>().SingleInstance();
builder.RegisterStateMachineSagas(Assembly.GetExecutingAssembly());
builder.Register(c => Bus.Factory.CreateUsingAzureServiceBus(sbc =>
{
var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", CloudConfigurationManager.GetSetting("AzureSbNamespace"), CloudConfigurationManager.GetSetting("AzureSbPath"));
sbc.UseLog4Net();
var host = sbc.Host(serviceUri, h =>
{
h.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(CloudConfigurationManager.GetSetting("AzureSbKeyName"), CloudConfigurationManager.GetSetting("AzureSbSharedAccessKey"), TimeSpan.FromDays(1), TokenScope.Namespace);
});
sbc.ReceiveEndpoint(host, CloudConfigurationManager.GetSetting("ServiceQueueName"), e =>
{
e.LoadFrom(c);
e.RequiresSession = true;
e.LoadStateMachineSagas(c);
e.MaxConcurrentCalls = 8;
e.EnableDeadLetteringOnMessageExpiration = false;
});
}))
.SingleInstance()
.As<IBusControl>()
.As<IBus>();
_container = builder.Build();
Trace.TraceInformation("POC has been started");
var bc = _container.Resolve<IBusControl>();
bc.Start();
Trace.TraceInformation("Masstransit has been started");
}
return result;
}
public override void OnStop()
{
Trace.TraceInformation("POC is stopping");
this.cancellationTokenSource.Cancel();
this.runCompleteEvent.WaitOne();
var bc = _container.Resolve<IBusControl>();
bc.Stop();
base.OnStop();
Trace.TraceInformation("POC has stopped");
}
private async Task RunAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
var bc = _container.Resolve<IBusControl>();
var id = Guid.NewGuid();
Trace.TraceInformation("Working - Publishing a new IStartPocMessage - {0}",id);
await bc.Publish<StartPocSagaMessage>(new { CorrelationId = id });
await Task.Delay(5000);
await bc.Publish<LoopMessage>(new { CorrelationId = id });
await Task.Delay(5000);
await bc.Publish<LoopMessage>(new { CorrelationId = id });
await Task.Delay(30000);
}
}
}
启动了8个传奇之后,它停止使用新消息。我根本不知道为什么会这样。
有没有人对这个问题有所了解?
提前致谢。