简体   繁体   English

具有多线程的RabbitMQ RPC生产者

[英]RabbitMQ RPC producer with Multithreading

How can i implement a RPC call in multithread environnement? 如何在多线程环境中实现RPC调用? In the basic tutorial here: https://www.rabbitmq.com/tutorials/tutorial-six-java.html , in multithread environnement, I see two problems: 在这里的基本教程中: https//www.rabbitmq.com/tutorials/tutorial-six-java.html ,在多线程环境中,我看到两个问题:

-If all is in different thread (including constructor), we create a reply queue for each thread, i don't thing it is a good idea (no ?) - 如果所有都在不同的线程(包括构造函数),我们为每个线程创建一个回复队列,我不是一个好主意(没有?)

-If only fibonacciRpc.call("4") is in different thread, the consumer for the reply queue can consume the bad reply, and the original consumer for this reply will wait indefinitely. - 如果只有fibonacciRpc.call(“4”)在不同的线程中,则回复队列的使用者可以使用错误的回复,并且此回复的原始使用者将无限期地等待。

I did not found any solution for now but maybe a I did not understand something. 我现在没有找到任何解决方案,但也许我不明白。

In my case : channel.basicConsume(replyQueueName, true, new DefaultConsumer(channel) {} is causing alot of heap size in memory and it does not gets cleared as long as i do not delete channel. 在我的例子中:channel.basicConsume(replyQueueName,true, new,DefaultConsumer(channel){}在内存中导致很多堆大小,只要我不删除通道就不会清除它。

As per Internet , you are supposed to create one connection. 根据Internet,您应该创建一个连接。 create channel per thread and create separate queue per channel and delete queue after you read the response , if you do not it will keep creating new queue over and over, in the same channel. 每个线程创建一个通道,并在读取响应后为每个通道创建单独的队列并删除队列,如果不这样,它将在同一个通道中反复创建新队列。

But new DefaultConsumer is creating alot of heap memory. 但新的DefaultConsumer正在创建大量的堆内存。

Looks like to get rid of this I have to delete channel. 看起来要摆脱这个我必须删除频道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM