pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
746 stars 144 forks source link

Help ! Explicitly specify exchange, queue and routing key and issue with routing key #368

Closed shah-keyur closed 5 years ago

shah-keyur commented 6 years ago

Hi Pardahlman,

I want to specify the exchange, queue name and routing key for consumer as well as publisher.

see the code below My Exchange Type is "DIRECT" public class Program { private static IBusClient _client;

    public static async Task Main(string[] args)
    {
        _client = BusClientFactory.CreateDefault(
            cfg => cfg
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("rawrabbit.json"),
            ioc => ioc
                .AddSingleton<IConfigurationEvaluator, AttributeConfigEvaluator>()
            );

        _client.SubscribeAsync<RabbitMQMessage>(ProcessMessage, cfg => cfg.WithQueue(q => q.WithName("raw-rabbit-queue"))
                                                                        .WithExchange(e => e.WithName("raw-rabbit-exchange").WithDurability())
                                                                        .WithRoutingKey("raw-rabbit-routing-key").WithPrefetchCount(100));

        for (int i = 0; i < 1000; i++)
        {
            await _client.PublishAsync(new RabbitMQMessage() { EventBody = "TEST Body " },
               default,
               cfg => cfg.WithExchange(e => e.WithName("raw-rabbit-exchange"))
                         .WithRoutingKey("raw-rabbit-routing-key"));
        }
    }

    public static async Task ProcessMessage(RabbitMQMessage message, MessageContext context)
    {
        Console.WriteLine("MessageConsumed:" + message.EventBody);
        await Task.CompletedTask;
    }
}

Somehow the routing key is generated with suffix '#' and GUID is missing. However, while publishing message it routes to a key+#+GUID.

Can't find much help to use with.Net Core(vNext). Then sample example is not much clear too.

It subscribes with ValuesRequested and Publishes ValuesCalculated.

Appreciate your help. Thanks, Keyur

kgrosvenor commented 5 years ago

I like the automatic namespacing of all this, apart from the queue name which i found to be inconsistent on different platforms, to fix that i did this

 cfg => cfg
                   .WithQueue(
                    q => q.
                     WithName(typeof(CreateGlucoseSummary).ToString()))
                    .WithSubscriberId(""));
pardahlman commented 5 years ago

@shah-keyur if you are running RawRabbit 1.x you could fix this by setting RouteWithGlobalId to false