标签: spring-rabbitmq

具有RabbitMQ连接问题的配置服务器

我在Rabbit代工厂运行RabbitMQ并尝试从本地运行的配置服务器连接,下面是在application.yml文件中配置的内容

  spring 
      rabbitmq:
        host: xxxx
        vhost: xxxx
        port: 5672
        username: xxx
        password: xxx
Run Code Online (Sandbox Code Playgroud)

抛出启动异常

org.springframework.context.ApplicationContextException: Failed to start bean 'outputBindingLifecycle'; nested exception is org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:852) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:98) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at …
Run Code Online (Sandbox Code Playgroud)

spring-cloud spring-rabbitmq

2
推荐指数
1
解决办法
2598
查看次数

在Spring-Boot-RabbitMQ中处理连接

嗨,我正在开发Spring-boot-RabbitMQ版本1.6。在开发应用程序时,我遇到的查询很少。阅读文档并浏览了其他堆栈溢出问题,但是我无法弄清楚几件事(可能是因为我的内存不好)。如果有人回答我的问题,那就太好了。

1)目前我有4个生产者和4个生产者。生产者可能产生数百万条消息或事件,因此对生产者和消费者使用单个连接将阻止消费者消费消息。生产者和消费者,这样它们就不会阻塞并且会改善性能。我对这种方法正确吗?

2)我正在使用CachingConnectionFactory来通过SimpleRabbitListenerContainerFactory创建连接,同时调用该工厂是否会为我们返回新的连接,因此如果我们使用CachingConnectionFactory,我们是否真的需要为Producer和Consumer编写一个单独的连接工厂。请在下面找到我的

1)配置类

@Configuration
@EnableRabbit
public class RabbitMqConfiguration{

@Autowired
private CachingConnectionFactory cachingConnectionFactory;

@Value("${concurrent.consumers}")
public int concurrent_consumers;

@Value("${max.concurrent.consumers}")
public int max_concurrent_consumers;

 @Bean
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(cachingConnectionFactory);
        factory.setConcurrentConsumers(concurrent_consumers);
        factory.setMaxConcurrentConsumers(max_concurrent_consumers);
        factory.setMessageConverter(jsonMessageConverter());
        return factory;
    }

@Bean
public MessageConverter jsonMessageConverter()
{
    final Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();
    return converter;
}

}
Run Code Online (Sandbox Code Playgroud)

2)生产者阶层

@Configuration
public class TaskProducerConfiguration extends RabbitMqConfiguration {

@Value("${queue1}")
public String queue1;

@Value("${queue2}")
public String queue2;

@Value("${queue3}")
public String …
Run Code Online (Sandbox Code Playgroud)

spring-rabbit spring-amqp spring-rabbitmq

2
推荐指数
1
解决办法
3962
查看次数

SpringBoot 1.5.1:健康端点未显示已注册的健康指标

我将spring boot版本从1.4.2升级到1.5.1.我的应用程序取决于RabbitMQ.

在使用版本1.4.2时,健康端点的输出是

{
  "status": "UP",
  "diskSpace": {
    "status": "UP",
    "total": 249779191808,
    "free": 160644202496,
    "threshold": 10485760
  },
  "rabbit": {
     "status": "UP",
     "version": "3.6.5"
  }
}
Run Code Online (Sandbox Code Playgroud)

升级后,使用1.5.1版输出

{
  "status": "UP"
}
Run Code Online (Sandbox Code Playgroud)

因此,磁盘空间和兔子指标不再存在.奇怪的是在日志中,我可以找到:

Registering bean definition for @Bean method org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$DiskSpaceHealthIndicatorConfiguration.diskSpaceHealthIndicatorProperties()
Registering bean definition for @Bean method org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$RabbitHealthIndicatorConfiguration.rabbitHealthIndicator() 
Run Code Online (Sandbox Code Playgroud)

甚至当我请求/健康端点时,我可以在日志中看到调用RabbitMq

o.s.amqp.rabbit.core.RabbitTemplate - Executing callback on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest@0:0:0:0:0:0:0:1:5672/,2), conn: Proxy@5292883 Shared Rabbit Connection: SimpleConnection@1aa1a795 [delegate=amqp://guest@0:0:0:0:0:0:0:1:5672/, localPort= 59527]
Run Code Online (Sandbox Code Playgroud)

预计,如果我关闭RabbitMQ实例的响应是

{
  "status": "DOWN"
}
Run Code Online (Sandbox Code Playgroud)

在我的application.ymlI中没有任何健康配置,因此使用默认配置.

如何获取健康端点的旧输出?

health-monitoring spring-boot spring-rabbitmq spring-boot-actuator

2
推荐指数
1
解决办法
1852
查看次数

慢速网络中的大RabbitMQ消息

我在Spring AMQP上使用RabbitMQ

  • 大邮件(> 100MB,102400KB)
  • 小带宽(<512Kbps)
  • 低心跳间隔(10秒)
  • 单一经纪人

使用该消息将花费> = 200 * 8秒,这超过了我的心跳间隔。从/sf/answers/2965457981/

如果节点之间的消息传输时间(60秒?)>节点之间的心跳时间,将导致群集断开连接并松动消息

  1. 即使我使用单一经纪人,我也会面临断开连接的问题吗?
  2. 心跳和使用者是否使用同一线程,如果使用者正在使用,则无法执行心跳?
  3. 如果是这样,在不增加心跳间隔或减小消息大小的情况下,如何使用该消息?

更新

发布自己的答案后,我还收到了另一个答案和评论。感谢您的反馈。只是为了澄清,我不使用AMQP进行文件传输。实际上,数据是在JSON消息中,一些简单而又小,但有些包含复杂的信息,包括一些手绘图。除了在Data Center中保存数据外,我们还通过AMQP在分支级别保存消息副本,以防无法连接到Data Center的情况。

rabbitmq spring-amqp spring-rabbitmq

2
推荐指数
1
解决办法
1597
查看次数

事务处理Rabbit MQ和Spring AMQP

我想在这里了解几件事。我的要求是,我想将记录存储在db中,并希望将消息发送到队列,然后如果抛出某些异常,则我希望以相同的方法说,我不想发送消息,也不想提交db事务。现在我想到了使用Spring事务,但是由于使用了两个不同的资源,想到了使用JTA使用一些atomikos来同步资源-但是我再次阅读了RMQ不支持2PC或XA等。无论如何,我继续尝试并没有添加atomikos首先尝试了所有这样做是为了确保我的频道已处理完毕,并且@Transaction批注已处理完毕,请参见下面的示例代码-我没有在pom中添加任何特殊内容。

现在我的问题是这是如何工作的,它与2PC有什么不同-方法可能出什么问题,什么情况会破坏使用此方法的最终一致性。令人惊讶的是,为什么我不必使用第三方jta。如果一切都很好-在我看来这最终保证了我们在使用Spring Goodies的rmq和db时的一致性!对于微服务:)

如果这不是一个好的解决方案,那有什么替代方案-如果可能的话,为了最终的一致性,我想避免使用工人流程等。

@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
    RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
    rabbitTemplate.setChannelTransacted(true);
    return rabbitTemplate;
}

@GetMapping
@Transactional
public void sampleEndpoint(@RequestParam boolean throwException){
    Customer a=new Customer();
    a.setCustomerName("XYZ");
    customerRepository.save(a);
    rabbitTemplate.convertAndSend("txtest","Test");
    if(throwException)
    throw new RuntimeException();
} 
Run Code Online (Sandbox Code Playgroud)

我在上面的示例中使用Spring Boot 1.5.7使用了postgres依赖关系

distributed-transactions spring-transactions spring-rabbit spring-amqp spring-rabbitmq

1
推荐指数
1
解决办法
2330
查看次数

Spring Boot RabbitMQ的任何单元和集成测试工具或框架?

我使用Spring boot和RabbitMQ为多个生产者和消费者开发了一个应用程序.应用程序工作正常没有任何问题,但我仍然想进行单元测试和集成测试.我浏览谷歌但没有运气没有得到坚实的用例来测试Spring boot和rabbitMQ在一起.

所以我想知道哪种工具最适合测试Spring Boot和RabbitMQ(至少有一个如何编写测试用例的提示是可观的)?我看到类似的stackoverflow帖子,但没有得到解决方案.你的帮助应该感激.

spring-integration rabbitmq spring-boot spring-rabbitmq

-1
推荐指数
1
解决办法
1762
查看次数