Exemplo n.º 1
0
        public IActionResult Index()
        {
            _RabbitmqSendService.Send(channel =>
            {
                channel.QueueDeclare(queue: "asp.netcore.web",
                                     durable: true,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);

                var body = Encoding.UTF8.GetBytes("Asp.net core rabbitmq");

                var bodyProperites        = channel.CreateBasicProperties();
                bodyProperites.Persistent = true;

                channel.BasicPublish(exchange: string.Empty,
                                     routingKey: "asp.netcore.web",
                                     mandatory: false,
                                     basicProperties: bodyProperites,
                                     body: body);
            });

            return(View());
        }
        public void Send_Basic_Message_Test()
        {
            var sendMessage = "Hello world";

            //send message
            _RabbitmqSendService.Send(channel =>
            {
                channel.QueueDeclare(queue: "test_queue",
                                     durable: false,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);

                var body = Encoding.UTF8.GetBytes(sendMessage);


                //note:publish's routingKey is queuename
                channel.BasicPublish(exchange: "",
                                     routingKey: "test_queue",
                                     basicProperties: null,
                                     body: body);
            });
        }