从响应队列返回值的问题

发布于 2024-09-24 14:40:15 字数 528 浏览 2 评论 0原文

我正在使用 Rabbitmq Java 客户端 API。我从 GUI 发送两个数字到生产者,生产者放入队列,另一端消费者可以监听队列并读取它,执行两个数字的加法并将结果放入队列,然后我的生产者将再次监听我的响应队列并检索结果。 代码:

while (runInfinite) { QueueingConsumer.Delivery 发货; 尝试 { 交付=消费者.nextDelivery(); } catch (InterruptedException 即) { 继续; } System.out.println("收到结果-" + new String(delivery.getBody())); 我的问题是,

当 while 循环无限运行时,我想将获取的结果发送到 GUI 以显示结果。我想知道,有可能吗?如果可能的话,我该怎么办?

谢谢

i am using Rabbitmq Java client API.i am sending two number from GUI to producer and producer put into queue another side consumer can listen the queue and read it and perform the addition of two number and put result on queue then again my producer will listen the my response queue and retrieve the result.
code:

while (runInfinite) {
QueueingConsumer.Delivery delivery;
try
{
delivery = consumer.nextDelivery();
} catch (InterruptedException ie)
{
continue;
}
System.out.println("Result received-"
+ new String(delivery.getBody()));
}

My problem is when the while loop run infinite time and i want to send the fetched result to an GUI to show result.i want to know that, it is possible ,if possible then what i do?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

z祗昰~ 2024-10-01 14:40:16

您可以使用两个队列。 GUI 将数字放入 1 个队列中。后台作业将其放入另一个队列。
但我不认为你想要像队列这样的东西来完成上述事情。

查看与您的 GUI 相关的事件操作和回调,看看它们是否适合您想要做的事情。

You can use two queues. The GUI puts the numbers in 1 queue. and the background job puts it another Queue.
But I do not think you want something like a queue to do the above thing.

Look at events actions and callbacks with respect to your GUI and see if they are suitable for the things you want to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文