0

I am using NServiceBus along with AzureServiceBus transport layer in my .net application. The publisher in .net core web application and the subscriber is .net core console application. Now the issue is I am publishing event for web application and in Azure portal I can see message count increasing after every publish event in Subscribers "Orders" under "bundle-1" topics created as default topic by NServiceBus in Azure Service Bus. But topic's "Active message count" is 0. But my subscriber is doing nothing means it's not listening. What am I doing wrong? Here is the publisher configuration:

            var endpointConfiguration = new EndpointConfiguration("Products");
            endpointConfiguration.EnableCallbacks();
            var instanceDiscriminator = "8e3af657-tt56-asd3-a75c-2fe8c4bcb635";
            endpointConfiguration.MakeInstanceUniquelyAddressable(instanceDiscriminator);
            var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
            transport.ConnectionString("connectionstring");
            var routing = transport.Routing();
            routing.RouteToEndpoint(
                assembly: typeof(OrderPlacedEvent).Assembly,
                destination: "Orders");
            endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
            services.AddSingleton<IMessageSession>(endpointInstance); 

and publishing code:

await _messageSession.Publish(new OrderPlacedEvent {OrderId = 1}).ConfigureAwait(false);

and subscriber's code:

            Console.Title = "Orders";

            IServiceCollection serviceProvider = new ServiceCollection();
            serviceProvider = Configuration.ConfigureService(serviceProvider);

            var endpointConfiguration = new EndpointConfiguration("Orders");
            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.UseSerialization<NewtonsoftSerializer>();
            endpointConfiguration.AuditProcessedMessagesTo("audit");
            endpointConfiguration.EnableInstallers();
            endpointConfiguration.UseContainer<ServicesBuilder>(customizations =>
            {
                customizations.ExistingServices(serviceProvider);
            });
            endpointConfiguration.UsePersistence<InMemoryPersistence>();
            var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
            transport.RuleNameShortener(n => n.Length > 50 ? MD5DeterministicNameBuilder.Build(n) : n);
            transport.ConnectionString("connectionString");
            var endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            Console.WriteLine("Press Enter to exit.");
            Console.ReadLine();

            endpointInstance.Stop().GetAwaiter().GetResult();

and the event:

public class OrderPlacedEvent : IEvent {}

Now I have a debugger attached in my handler but it never gets hit. One more thing I also have some commands and the commands are working fine. The message counter of Queue gets updated when ever I send any command and subscriber always listen to commands. One last thing to mention I am using free trial of Azure portal but I think that wouldn't be an issue because commands are working fine. Any help?

mason
  • 31,774
  • 10
  • 77
  • 121
Ask
  • 3,076
  • 6
  • 30
  • 63
  • You should avoid these GetAwaiter().GetResult() calls. If you're making async calls, you should `await` them. Your console app's main method can be made async as long as you target C# 7.1 or above. – mason Feb 14 '19 at 14:49
  • yes, I know that can be made async. Could that be an issue? I can try with that – Ask Feb 14 '19 at 14:50
  • I don't know, I've never used NServiceBus before. But I do know that `.GetAwaiter().GetResult()` is to be avoided, and besides that it's overly verbose. – mason Feb 14 '19 at 14:54
  • I've noticed this one is a duplicate of the [issue](https://github.com/Particular/NServiceBus/issues/5328) raised in GitHub. Everything looks good, except the routing of the event type in the publisher. That part should not be there. Try removing that. – Sean Feldman Feb 14 '19 at 18:10

0 Answers0