如何提取rabbitmq接收方法

编程入门 行业动态 更新时间:2024-10-15 12:38:20
本文介绍了如何提取rabbitmq接收方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,我正在尝试用tutoria学习rabbitmq( RabbitMQ - RabbitMQ教程 - 你好世界! [ ^ ])。当我想将接收代码块提取到NewMethod函数时,并在Main方法中使用NewMethod。我无法在队列中收到消息。任何人都可以提供帮助,非常感谢。 这是我的Receive.cs代码。

Hi everyone, I'm trying to learn rabbitmq with the tutoria(RabbitMQ - RabbitMQ tutorial - "Hello World!"[^]). When I want to extract the receieve code block to a function as NewMethod, and use the NewMethod in Main method. I cannot receive the message in the queue. Anyone can help, thanks a lot. here are my Receive.cs code.

<pre> public static void Main() { Console.WriteLine("message from NewMethod:" + NewMethod()); Console.ReadLine(); } static string NewMethod() { string message = string.Empty; var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { var body = ea.Body; message = Encoding.UTF8.GetString(body); Console.WriteLine("[x] Received {0}", message); }; channel.BasicConsume(queue: "hello", noAck: true, consumer: consumer); } return message; }

我的尝试: 我尝试过没有返回值的函数。但也失败

What I have tried: I have tried function without return value. but also failed

推荐答案

请参阅 RabbitMQ - RabbitMQ社区 [ ^ ]。

更多推荐

如何提取rabbitmq接收方法

本文发布于:2023-11-25 04:57:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628420.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   rabbitmq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!