Subscriber is unable to handler message from publisher - nservicebus

I'm testing NServiceBus on ASP.NET MVC3. At the moment, I'm able to send command message to the backend and the message handler is listening to it. But when i try to publish the same message, the message handler is not listening.
The problem i found is that message is not published to the subscriber's queue. When i debug and check NServiceBusHost console, it says
2012-01-19 22:53:35,042 [1] INFO NServiceBus.Unicast.UnicastBus [(null)] <(null
)> - Subscribing to SampleMessage.Person1WasCreated, SampleMessage, Version=1.0.
0.0, Culture=neutral, PublicKeyToken=null at publisher queue Test-web
I checked my config settings again and again for few days and it seems correct for me . Can anyone please check for me what I'm missing? The thing I'm trying to do is to publish a message from the web and the message should be handle at the backend (ServiceHost2).
ASP.NET MVC3 Web.config
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="MsmqSubscriptionStorageConfig" type="NServiceBus.Config.MsmqSubscriptionStorageConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
</configSections>
<MsmqTransportConfig InputQueue="Test-web" ErrorQueue="Test-web-error" NumberOfWorkerThreads="1" MaxRetries="5" />
<MsmqSubscriptionStorageConfig Queue="Test-subscriptionstorage" />
Global.asax.cs
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
Global.Bus = Configure.WithWeb()
.Log4Net()
.CastleWindsorBuilder()
.XmlSerializer()
.MsmqTransport().IsTransactional(false)
.UnicastBus()
.LoadMessageHandlers()
.MsmqSubscriptionStorage()
.CreateBus()
.Start()
;
}
App.Config in ServiceHost2 Project
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="MsmqSubscriptionStorageConfig" type="NServiceBus.Config.MsmqSubscriptionStorageConfig, NServiceBus.Core" />
</configSections>
<MsmqSubscriptionStorageConfig Queue="Service2-AC1-subscriptionstorage" />
<MsmqTransportConfig InputQueue="Service2-AC1" ErrorQueue="Service2-AC1-Error" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="SampleMessage" Endpoint="Test-web" />
</MessageEndpointMappings>
</UnicastBusConfig>
<appSettings>
<add key="EndpointConfigurationType" value="ServiceHost2.EndpointConfig, ServiceHost2"/>
</appSettings>
</configuration>
EndpointConfig for ServiceHost2
namespace ServiceHost2
{
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
public void Init()
{
Configure.With()
.Log4Net()
.CastleWindsorBuilder()
.MsmqTransport()
.MsmqSubscriptionStorage()
.XmlSerializer()
.UnicastBus().LoadMessageHandlers()
;
}
}
}
Method in the controller which publish the message
public ActionResult CreatePerson(Person p)
{
var Person1WasCreated = new Person1WasCreated {Id = p.Id,Name = p.Name};
Global.Bus.Publish(Person1WasCreated);
return View();
}
Thanks.

I think I found out why. I was reading on this article today about Why not publish NServiceBus messages from a web application?
It states very clear that, message is not suppose to publish from the web. Somehow The subscription storage created by my web project doesn't allow anything to subscribe to it.
So my solution is, I send the command message from the web to a message handler in Service1, and publish a new event message to Service2. Even the event message is able to subscribe into Service1's subscription storage.Everything works fine now. Thanks.

Related

NServiceBus : Error messages does not appear in Error queue - ForwarderFaultManager does not start

I am running NServiceBus 5.2.14 with NServiceBus.Host 6.0.0
I am using MSMQ as transport and RavenDBPersistence.
All queues appear in computer management except for the error queue.
Everything functions fine for messages and endpoints. Errors are retried 5 times as they should. However after retrying 5 times they do not appear in the error queue.
I have specified the error queue in as such:
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
and included in configSections:
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
Edit1: app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="TransportConfig" type="NServiceBus.Config.TransportConfig, NServiceBus.Core" />
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
</configSections>
<TransportConfig MaximumConcurrencyLevel="5" MaxRetries="5" />
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
<UnicastBusConfig ForwardReceivedMessagesTo="audit">
<MessageEndpointMappings>
...
</MessageEndpointMappings>
</UnicastBusConfig>
...
Edit2 : endpointconfig:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
...
public void Customize(BusConfiguration busConfiguration)
{
...
var containerFactory = new ContainerFactory();
Container.InitializeContainer(containerFactory);
AutoMapperInitializer.Configure();
busConfiguration.AssembliesToScan(AllAssemblies.Matching("NServiceBus").And("OurProjectName."));
busConfiguration.UseTransport<MsmqTransport>();
busConfiguration.EndpointName(ConfigurationManager.AppSettings["InputQueueName"]);
busConfiguration.UseContainer<WindsorBuilder>(customizations => customizations.ExistingContainer(Container.Instance));
busConfiguration.UsePersistence<RavenDBPersistence>();
busConfiguration.EnableCriticalTimePerformanceCounter();
busConfiguration.RegisterComponents(components => { components.ConfigureComponent<UsernameForwarder>(DependencyLifecycle.InstancePerCall); });
...
}
}
I run the endpoints in self-hosting console. In the list of FEATURES I see this:
Name: ForwarderFaultManager
Version: 5.2.14
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not meet one of the dependencies:
Name: InMemoryFaultManager
Version: 5.2.14
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
I suspect my problem is with the ForwarderFaultManager, however there is nothing listed in the missing dependencies list. What may I be missing? Where could I start looking?

Release 5.0.0 NServiceBus fails to start

I have an NServiceBus.Host.exe.config configuration as follows:
I get this error:
2014-08-07 16:30:33.842 ERROR NServiceBus.GenericHost Exception when starting endpoint.
System.Configuration.ConfigurationErrorsException: Faults forwarding requires an error queue to be specified. Please add a 'MessageForwardingInCaseOfFaultConfig' section to your app.config
or configure a global one using the powershell command: Set-NServiceBusLocalMachineSettings -ErrorQueue {address of error queue}
at NServiceBus.Faults.Forwarder.ForwarderFaultManager.Setup(FeatureConfigurationContext context) in d:\Development\Github\NServiceBus\src\NServiceBus.Core\Faults\Forwarder\ForwarderFaultManager.cs:line 54
at NServiceBus.Features.FeatureActivator.ActivateFeature(FeatureState feature, List`1 featuresToActivate, FeatureConfigurationContext context) in d:\Development\Github\NServiceBus\src\NServiceBus.Core\Features\FeatureActivator.cs:line 186
at NServiceBus.Features.FeatureActivator.SetupFeatures(FeatureConfigurationContext context) in d:\Development\Github\NServiceBus\src\NServiceBus.Core\Features\FeatureActivator.cs:line 115
at NServiceBus.Configure.Initialize() in d:\Development\Github\NServiceBus\src\NServiceBus.Core\Configure.cs:line 197
at NServiceBus.GenericHost.Start() in d:\Development\Github\NServiceBus\src\NServiceBus.Hosting.Windows\GenericHost.cs:line 58
The configuration file is as follows.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig,
NServiceBus.Core" />
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
</configSections>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error"/>
<MsmqTransportConfig NumberOfWorkerThreads="1" MaxRetries="5"/>
</configuration>
Endpoint configuration looks like this:
class EndpointConfig : IConfigureThisEndpoint, INeedInitialization
{
public void Customize(ConfigurationBuilder builder)
{
builder.Conventions(c => c
.DefiningMessagesAs(t => t.Namespace != null && t.Namespace.EndsWith("RequestResponse")));
}
public void Init(Configure config)
{
}
}
Your error queue is not is not created.
Try creating your queue manually and run it again.

How to register NServiceBus.Timeout.Core.ImanageTimeouts

I have an NServiceBus publisher project that has ran successfully for months. It was using NServiceBus.Host version 3.2.2. I need to upgrade the version to 3.3.8. After the upgrade, I get the following exception notification:
Exception when starting endpoint, error has been logged. Reason: The requested service 'NServiceBus.Timeout.Core.IManageTimeouts' has not been registered.
To avoid this exception, either register a component to provide the service,
check for service registration using IsRegistered(),
or use the ResolveOptional() method to resolve an optional dependency.
I have searched online to determine why NServiceBus.Host version 3.3.8 would not register IManageTimeouts object. I have also searched for documentation or examples using IsRegistered() and ResolveOptional(). No luck so far... (Maybe I need a semester at Google search university?)
Has any NServiceBus users out there experienced this exception?
Is the IManageTimeouts object new to NServiceBus.Host version 3.3.8?
Could someone provide an example how I could register the IManageTimeouts object with NServiceBus
configuration?
Here are my current configuration settings:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig ErrorQueue="PublisherError" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig ForwardReceivedMessagesTo="">
<MessageEndpointMappings></MessageEndpointMappings>
</UnicastBusConfig>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="PublisherFault" />
/configuration>
configure = NServiceBus.Configure.With();
Bus = configure
.DefiningMessagesAs(t => t.Namespace != null && t.Namespace.EndsWith("EventPublisher.InternalMessages"))
.DefineEndpointName("EventPublisher")
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.UnicastBus()
.LoadMessageHandlers()
.ImpersonateSender(false)
.CreateBus()
.Start(() => Configure.Instance.ForInstallationOn<Windows>().Install());
It looks like you need to explicitly enable TimeoutManager.
To do that:
.UseRavenTimeoutPersister();

Unsatisfied dependency expressed through object property

So I am building publisher and following is my config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="DBSubscriptionStorageConfig" type="NServiceBus.Config.DBSubscriptionStorageConfig, NServiceBus.Core" />
</configSections>
<!-- 1. In order to configure remote endpoints use the format: "queue#machine"
2. Input queue must be on the same machine as the process feeding off of it.
3. Error queue can (and often should) be on a different machine.
4. The community edition doesn't support more than one worker thread.
-->
<MsmqTransportConfig
InputQueue="HomeOfficePublisherQueue"
ErrorQueue="error"
NumberOfWorkerThreads="1"
MaxRetries="5"
/>
<DBSubscriptionStorageConfig>
<NHibernateProperties>
<add Key="connection.provider"
Value="NHibernate.Connection.DriverConnectionProvider"/>
<add Key="connection.driver_class"
Value="NHibernate.Driver.SqlClientDriver"/>
<add Key="connection.connection_string"
Value="Server=<dbserver>;initial catalog=NServiceBus;Integrated Security=SSPI"/>
<add Key="dialect"
Value="NHibernate.Dialect.MsSql2005Dialect"/>
</NHibernateProperties>
</DBSubscriptionStorageConfig>
<UnicastBusConfig
DistributorControlAddress=""
DistributorDataAddress=""
ForwardReceivedMessagesTo="">
<MessageEndpointMappings>
</MessageEndpointMappings>
</UnicastBusConfig>
</configuration>
and here is my endpoint
class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
public void Init()
{
NServiceBus.Configure.With()
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.UnicastBus()
.ImpersonateSender(false)
.MsmqTransport()
.IsTransactional(true)
.DBSubcriptionStorage();
}
}
}
I get following exception
Exception when starting endpoint, error has been logged. Reason: Error creating object with name 'NServiceBus.Unicast.UnicastBus' : Unsatisfied dependency expressed through object property 'SubscriptionStorage': There are 2 objects of Type [NServiceBus.Unicast.Subscriptions.ISubscriptionStorage] for autowire by type, when there should have been just 1 to be able to autowire property 'SubscriptionStorage' of object 'NServiceBus.Unicast.UnicastBus'.
Any help is appreciated
I just had the same problem, and solved it by calling .CreateBus() at the end of the configuration:
class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
public void Init()
{
NServiceBus.Configure.With()
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.UnicastBus()
.ImpersonateSender(false)
.MsmqTransport()
.IsTransactional(true)
.DBSubcriptionStorage()
.CreateBus();
}
}
Only use the roles if their settings are what you want. Try to remove As_aPublisher and see if that does it for you. In your case both the role and your own code will register a sub.storeage and that is what gives you the exception.

"No message serializer has been configured" error when starting NServiceBus endpoint

My GenericHost hosted service is failing to start with the following message:
2010-05-07 09:13:47,406 [1] FATAL NServiceBus.Host.Internal.GenericHost [(null)] <(null)> - System.InvalidOperationException: No message serializer has been con
figured.
at NServiceBus.Unicast.Transport.Msmq.MsmqTransport.CheckConfiguration() in d:\BuildAgent-02\work\672d81652eaca4e1\src\impl\unicast\NServiceBus.Unicast.Msmq\
MsmqTransport.cs:line 241
at NServiceBus.Unicast.Transport.Msmq.MsmqTransport.Start() in d:\BuildAgent-02\work\672d81652eaca4e1\src\impl\unicast\NServiceBus.Unicast.Msmq\MsmqTransport
.cs:line 211
at NServiceBus.Unicast.UnicastBus.NServiceBus.IStartableBus.Start(Action startupAction) in d:\BuildAgent-02\work\672d81652eaca4e1\src\unicast\NServiceBus.Uni
cast\UnicastBus.cs:line 694
at NServiceBus.Unicast.UnicastBus.NServiceBus.IStartableBus.Start() in d:\BuildAgent-02\work\672d81652eaca4e1\src\unicast\NServiceBus.Unicast\UnicastBus.cs:l
ine 665
at NServiceBus.Host.Internal.GenericHost.Start() in d:\BuildAgent-02\work\672d81652eaca4e1\src\host\NServiceBus.Host\Internal\GenericHost.cs:line 77
My endpoint configuration looks like:
public class ServiceEndpointConfiguration
: IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
public void Init()
{
// build out persistence infrastructure
var sessionFactory = Bootstrapper.InitializePersistence();
// configure NServiceBus infrastructure
var container = Bootstrapper.BuildDependencies(sessionFactory);
// set up logging
log4net.Config.XmlConfigurator.Configure();
Configure.With()
.Log4Net()
.UnityBuilder(container)
.XmlSerializer();
}
}
And my app.config looks like:
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="Logging" type="NServiceBus.Config.Logging, NServiceBus.Core" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
</configSections>
<Logging Threshold="DEBUG" />
<MsmqTransportConfig
InputQueue="NServiceBus.ServiceInput"
ErrorQueue="NServiceBus.Errors"
NumberOfWorkerThreads="1"
MaxRetries="2" />
<UnicastBusConfig
DistributorControlAddress=""
DistributorDataAddress=""
ForwardReceivedMessagesTo="NServiceBus.Auditing">
<MessageEndpointMappings>
<!-- publishers don't need to set this for their own message types -->
</MessageEndpointMappings>
</UnicastBusConfig>
<connectionStrings>
<add name="Db" connectionString="Data Source=..." providerName="System.Data.SqlClient" />
</connectionStrings>
<log4net debug="true">
<root>
<level value="INFO"/>
</root>
<logger name="NHibernate">
<level value="ERROR" />
</logger>
</log4net>
This has worked in the past, but seems to be failing when the generic host starts. My endpoint configuration is below, along with the app.config for the service. What is strange is that in my endpoint configuration, I am specifying to use the XmlSerializer for message serialization. I don't see any other errors in the console output preceding the error message. What am I missing?
Thanks, Steve
It looks like this was my own issue, though I had a hard time figuring that out based on the error message that I received. I have a base class for all of my messages:
public abstract class RequestMessage : IMessage {}
Recently, I created a partner message:
public abstract class ResponseMessage<TRequest>
where TRequest : RequestMessage {}
Apparently, when the host was starting up the IStartableBus, it would hit this generic message type and would not handle it correctly. I only really saw the underlying error when running with the DefaultBuilder, rather than the UnityBuilder that I am using in my project. It had something to do with the generic type constraint. I had assumed that this would work, but sadly it did not.
Regards,
Steve