0
votes

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; }
}

}

1
Obviously the "queue-end-point-address" is not right. - Alexey Zimarev
Did you figure this out? It's likely that your queue send address isn't correct, you can check the InputAddress property of your receive endpoint to see what it should look like to verify. Also, you don't need a {set;} on your ISayHello interface. - Chris Patterson
Yes. It was an issue with queue address - Thanks for pointing it out @ChrisPatterson - Binu

1 Answers

1
votes

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