Binu
Binu

Reputation: 145

MassTransit Consumer not getting called

In the following sample program (using MassTransit, Azure ServiceBus), I am able to send messages to the queue, but my Receive Endpoint/Consumer does not seems to get the message. What am I doing wrong here? (Simple publish and a handler example given in this link(http://masstransit-project.com/MassTransit/quickstart.html) works fine!)

    static async Task MainAsync(string[] args)
    {
        var bus = Bus.Factory.CreateUsingAzureServiceBus(cfg =>
        {
            var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", "{sb}", "{sb-name}");
            var host = cfg.Host(serviceUri, h =>
            {
                h.OperationTimeout = TimeSpan.FromSeconds(5);
                h.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(
                    "RootManageSharedAccessKey",
                    "{key}");
                h.TransportType = TransportType.NetMessaging;

            });

            cfg.ReceiveEndpoint(host, "test_queue", ep =>
            {
                ep.Consumer<SayHelloCommandConsumer>();
            });
        });


        bus.Start();

        await SendAHello(bus);

        Console.WriteLine("Press any key to exit");
        Console.ReadKey();

        bus.Stop();
    }

    private static async Task SendAHello(IBusControl bus)
    {

        var sendToUri = new Uri("queue-end-point-address");
        var endPoint = await bus.GetSendEndpoint(sendToUri);
        await endPoint.Send<ISayHello>( new
            {
                Message = "Hello there !"
            });
    }
}
public class SayHelloCommandConsumer : IConsumer<ISayHello>
{
    public Task Consume(ConsumeContext<ISayHello> context)
    {
        var command = context.Message;
        return Console.Out.WriteLineAsync($"Recieved a message {command}");
    }
}

public interface ISayHello
{
    string Message { get; set; }
}

}

Upvotes: 0

Views: 2425

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33278

The queue address looked suspect, and it seems like you've corrected it.

Upvotes: 2

Related Questions