I'm using rebus with Autofac integration for webapi
Below is my configuration statement called on Application_Start of Global.asax.cs
When the app pool is restarted it doesn't recognise the subscriptions for events of a service listening to events published by the webapi, so the result is
DEBUG 09:56:12.842 dd2c1f8c-370d-4bd4-828c-27f033dfabdf RebusConfigurer+<>c.0 Sending Events.UserLoggedIn -> << no destinations>>
I need to restart the service for the webapi to receive subscriptions requests
I can see the configuration taken place with
DEBUG 09:55:50.744 890204c2-1dcb-4df0-9525-d6585d9692cb RebusAutofacConfig.25 Configuring rebus in queue :'xyz'
DEBUG 09:55:50.864 890204c2-1dcb-4df0-9525-d6585d9692cb RebusAutofacConfig.33 Configured rebus with 1 workers
Here is my webapi configuration to publish messages
public static class RebusAutofacConfig
{
private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
internal static IContainer ConfigureRebus(this IContainer container)
{
var inputQueueName = System.Configuration.ConfigurationManager.AppSettings["queueName"];
if (inputQueueName.IsNullEmptyOrWhisteSpace())
{
inputQueueName = "xyz";
}
var errorQueue = inputQueueName + ".errors";
Logger.DebugFormat("Configuring rebus in queue :'{0}'", inputQueueName);
var bus = Configure
.With(new AutofacContainerAdapter(container))
.Serialization(s => s.UseJil(Jil.Options.IncludeInherited))
.Logging(l => l.Log4Net())
.Transport(t => t.UseMsmq(inputQueueName))
.Options(b => b.SimpleRetryStrategy(errorQueue, 5, true))
.Start();
Logger.DebugFormat("Configured rebus with {0} workers", bus.Advanced.Workers.Count);
return container;
}
}
Here is my windows service configuration to listen to messages
internal static IContainer ConfigureRebus(this IContainer container, ISettings settings)
{
Configure
.With(new AutofacContainerAdapter(container))
.Serialization(s => s.UseJil(Jil.Options.IncludeInherited))
.Logging(l => l.Log4Net())
.Transport(t => t.UseMsmq(settings.EventsQueueName))
.Routing(r => r.TypeBased().MapAssemblyOf<UserLoggedIn>(inputQueueName))
.Options(o => o.SimpleRetryStrategy(settings.EventsErrorQueueName, 5, true))
.Options(o =>
o.SpecifyOrderOfHandlers()
.First<UserCacheHandler>()
.Then<UserCreatedResetPasswordHandler>()
)
.Events(e =>
{
e.BeforeMessageHandled += (bus, headers,message, context, args) =>
{
System.Diagnostics.Trace.CorrelationManager.ActivityId = Guid.NewGuid();
};
})
.Start();
return container;
}
Seems like after the apppool is restarted no subscription is recognized.
I'm using a local Msmq.
Any ideas what can I be doing wrong?
From the configurations you posted, it looks like you are not storing your subscriptions anywhere.
This means that your Web API is storing subscription in memory, which explains why you always seem to have to start your processes in the
order.
Since MSMQ is a transport WITHOUT native pub/sub support (at least the way Rebus is using it), you need to configure a (persistent!) subscription storage for your scenario to work.
If you have e.g. a SQL Server available, I suggest you configure your Web API to use it to store subscriptions. It's done by importing the Rebus.SqlServer
package, and then you go
.Subscriptions(s => s.StoreInSqlServer(...))
in the configuration spell.
You can read more about configuring a subscription storage on the wiki page about ISubscriptionStorage
.