0

How can i publish and receive message i tried like this code below it makes queue and exchange but nothing message coming to my app? What i am doing wrong?

    //Publisher
    public static IBusClient GetBusClient()
            {
                var config = new RawRabbitConfiguration
                {
                    Hostnames = { "localhost" },
                    Port = 5672,
                    VirtualHost = "/",
                    Username = "guest",
                    Password = "guest"
                };
                var client = BusClientFactory.CreateDefault(config);
                return client;
            } 
            static  void Main(string[] args)
            {
                string message = "Hello World";
                const string EXCHANGE_NAME = "myRabbit";
                Action<IPublishConfigurationBuilder> x = (ctx) => ctx.WithExchange(x => x.WithName(EXCHANGE_NAME));
                var _bus = GetBusClient();
                 _bus.PublishAsync(new BasicMessage { Message = message }, Guid.NewGuid(), x);
            }

//Subscribber
        public static void Main(string[] args)
        {

            var bus = GetBusClient();
            bus.SubscribeAsync<SubMsg>(async (msg, context) =>
            {
                Console.WriteLine($"{msg.Message}.");
                await Task.FromResult(true);
            }, ctx => ctx.WithExchange(x => x.WithName("myRabbit").WithAutoDelete(false).WithDurability(true)).WithQueue(x => x.WithName("myConsole").WithExclusivity(false).WithDurability(true).WithAutoDelete(false)));
            Console.ReadLine();
        }
Splitsan
  • 135
  • 8
  • is it because you are publishing `BasicMessage` but subscribed for `SubMsg` ? – oleksa Mar 19 '20 at 07:50
  • i change names to same but it didn't help – Splitsan Mar 19 '20 at 07:53
  • in this case you can try with the [official sample](https://github.com/pardahlman/RawRabbit/blob/2.0/sample/RawRabbit.ConsoleApp.Sample/Program.cs) and adjust it accordingly. Probably you have to wait after `_bus.PublishAsync` call like `_bus.PublishAsync().Wait()` to make sure that publish task has been completed before `Main()` ends – oleksa Mar 19 '20 at 08:02
  • Now i got an error [17:48:04] [$5] [INFO] [EventingBasicConsumerFactory]: Message recived: MessageId: 47097db8-917c-47ea-a775-1ebf32b89521 [17:48:06] [$4] [INFO] [TopologyProvider]: Disposing topology channel (if exists). Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON 'Rabit20.Sender, Rabit20'. Path '$type', line 1, position 44. ---> Newtonsoft.Json.JsonSerializationException: Could not load assembly 'Rabit20'. .DefaultSerializationBinder.GetTypeFromTypeNameKey(StructMultiKey`2 typeNameKey) at System.Collections.Concurrent – Splitsan Mar 19 '20 at 16:49
  • well. Seems that you can send message successfully. Is there `Rabit20` assembly available on both sender and receiver? – oleksa Mar 20 '20 at 07:17
  • finally i found solution, i make one project with model and shared between projects publisher/subscriber two of them and now no problem with json it works fine now, thank you for advises :) – Splitsan Mar 20 '20 at 17:40

0 Answers0