rabbitmq客户端在尝试声明队列时挂起

时间:2018-01-16 06:52:27

标签: rabbitmq spring-rabbitmq

我尝试搜索我的问题的解决方案,但找不到堆栈溢出。

问题 当用户尝试声明队列或交换时,在RabbitMQ服务器出现问题的极端情况下,客户端保持等待而没有任何超时,这导致调用rabbitmq的线程始终保持等待状态(等待永远不会结束)。

下面是stacktrace

java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:502)
    at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:50)
    - locked <0x00000007bb0464c8> (a com.rabbitmq.utility.BlockingValueOrException)
    at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:89)
    - locked <0x00000007bb0464c8> (a com.rabbitmq.utility.BlockingValueOrException)
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216)
    at 
(AMQChannel.java:118)
    at com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:833)
    at com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:917)
    - locked <0x00000007bb555300> (a java.lang.Object)
    at com.sun.proxy.$Proxy293.queueDeclare(Unknown Source)
    at org.springframework.amqp.rabbit.core.RabbitAdmin.declareQueues(RabbitAdmin.java:575)
    at org.springframework.amqp.rabbit.core.RabbitAdmin.access$200(RabbitAdmin.java:66)
    at org.springframework.amqp.rabbit.core.RabbitAdmin$12.doInRabbit(RabbitAdmin.java:504)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1456)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1412)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1388)
    at org.springframework.amqp.rabbit.core.RabbitAdmin.initialize(RabbitAdmin.java:500)
    at org.springframework.amqp.rabbit.core.RabbitAdmin$11.onCreate(RabbitAdmin.java:419)
    at org.springframework.amqp.rabbit.connection.CompositeConnectionListener.onCreate(CompositeConnectionListener.java:33)
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:553)
    - locked <0x00000007bb057828> (a java.lang.Object)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1431)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1412)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1388)
    at org.springframework.amqp.rabbit.core.RabbitAdmin.declareQueue(RabbitAdmin.java:207)

任何帮助都将受到高度赞赏。队列声明目前在我的bean的postconstruct中调用我们的组件处理消息传递,因此不会让任何新bean创建。

更新 问题在我们的prod服务器上再次出现。当试图通过amqp-client-3.4.2直接连接它似乎工作。但是从spring-rabbit-1.6.7.RELEASE,spring-amqp-1.6.7.RELEASE它无效。

通过amqp-client-3.4.2

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("<<HOST NAME>>");
        factory.setUsername("<<USERNAME>>");
        factory.setPassword("<<PASSWORD>>");
        factory.setVirtualHost("<<VIRTUAL HOST>>");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME, true, false, false, null);

Code flow with rabbit-amqp client

不起作用的春天方式

        CachingConnectionFactory factory = new CachingConnectionFactory();
        factory.setHost("<<HOST NAME>>");
        factory.setUsername("<<USERNAME>>");
        factory.setPassword("<<PASSWORD>>");
        factory.setVirtualHost("<<VIRTUAL HOST>>");

        RabbitAdmin admin = new RabbitAdmin(factory);
        Queue queue = new Queue(QUEUE_NAME);
        admin.declareQueue(queue);

Code flow with spring amqp

这个问题很少发生,我们仍在试图弄清楚这种行为背后的原因。我们尝试设置连接超时但在我们的测试程序中没有用。

进一步调试时,看起来异常不会让通知发送回我们的代码。对于没有发现问题的客户,我们正在适当地获得例外。

我们在CentOS Linux 7(核心)上使用RabbitMQ 3.6.10和Erlang 19.3.4

1 个答案:

答案 0 :(得分:1)

  

队列声明目前在我的bean的后期构建中

我不能说话,但你永远不应该从post构造,afterPropertiesSet()等与代理进行交互。在应用程序上下文生命周期中还为时过早。

有几种解决方法 - 实施SmartLifecycle;从true返回isAutoStartup()并将bean置于早期阶段(参见Phased)。完全创建应用程序上下文后,将调用start()

但是,通常最好将队列,绑定等定义为bean,并让框架负责为您完成所有声明。