- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
org.springframework.web.context.ContextLoader | localhost-startStop-1 | Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleListenerContainer' defined
in class path resource [com/company/product/api/config/amqp/InternalAmqpConfiguration.class]: Bean instantiation v
ia factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
如果在我的 Spring MVC 应用程序启动之前 Rabbit 已关闭,则依赖于 CachingConnectionFactory 的许多 Bean 将无法初始化。就像下面这样:
@Autowired
@Bean
public SimpleRabbitListenerContainerFactory simpleistenerContainer(
@Qualifier("internal") CachingConnectionFactory connectionFactory,
RabbitAdmin admin) {
for(Listeners listener : Listeners.values()) {
Queue q = new Queue(listener.queue, true, true, true);
admin.declareQueue(q);
admin.declareBinding(
BindingBuilder.bind(q)
.to(new TopicExchange(listener.exchange, true, false))
.with((listener.appendWildcard) ? listener.routingKey + ""
+ ".*" : listener.routingKey)
);
}
SimpleRabbitListenerContainerFactory listenerContainerFactory = new
SimpleRabbitListenerContainerFactory();
listenerContainerFactory.setConnectionFactory(connectionFactory);
return listenerContainerFactory;
}
此操作失败并且无法恢复,因为缺少此依赖项之一而导致 Bean 未初始化。我考虑过在 CachingConnectionFactory
上设置 ConnectionListener
,但这些对象将无法作为 bean 访问。任何的意见都将会有帮助。我确信可能有一个简单的解决方案。
最佳答案
只需将您的绑定(bind)等添加为 @Bean
,而不是自己声明它们。
添加一个RabbitAdmin
@Bean
,它会在建立连接时自动执行声明。
编辑:
回应您的评论...
但是,您正在执行自己的声明:
admin.declareQueue(q);
admin.declareBinding(...
如果代理不可用,除非您添加 try/catch,否则这些操作将会失败。您还可以在管理员上设置 ignoreDeclarationExceptions
,但您实际上不需要自己执行这些声明。一旦容器建立连接,管理员就会自动声明它们。
编辑2:
Why would they get declared? ...
因为这就是它的设计方式;请阅读the documentation向下滚动查看Binding
等的java配置
RabbitAdmin
(如果在上下文中声明)将自身注册为连接监听器。建立连接后,管理员会在上下文中查找所有 Queue
、Exchange
和 Binding
@Bean
,并在建立连接时声明它们。
您通过直接从 bean 定义进行绑定(bind)来破坏此“惰性”声明,这要求代理可用,并且如果没有连接,上下文将无法初始化。
只需在上下文中声明您所需的Binding
,管理员就会在代理可用时为您处理。监听器容器将根据其 recoveryInterval
继续尝试连接,并且最终成功时将发生声明。
关于java - 当rabbit最初关闭时,Bean无法初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30130034/
我必须用兔子、松鼠、狼和猎豹填充我的网格。我正在寻找字符串到类型对象的映射 populate("CHEETAH", 2); populate("WOLF", 3); populate("SQUIRRE
我们正在对业务异常进行重试操作,并使用 MessageRecoverer 进行几次尝试后存储消息,因此我们在 XML 中对重试进行了第一个配置,例如最大尝试次数和间隔等。在此链接中重试的属性 http
我目前正在研究 Rabbit-Mq,并试图实现一个“死信”队列,一个用于失败消息的队列。我一直在阅读兔子文档:https://www.rabbitmq.com/dlx.html . 并想出了这个例子:
我正在尝试使用 devstack 在 Ubuntu 12.04 上设置 OpenStack。现在,我得到的错误是: Setting up rabbitmq-server (2.7.1-0ubuntu4
我们有一个 RabbitMQ 交换器,它在我们系统的几个组件之间交换消息。 每个组件都是交易所的发布者和订阅者。 我们需要找到一种方法来确保每个应用程序都不会收到它发送到交换中的消息。 例如。 应用
我有一个不寻常的情况,如果我的应用程序在消息处理过程中已正常关闭(例如自动缩放),我不希望将带有重新传递标志的消息发送回队列。我希望仅在应用程序崩溃时才设置该标志。我的代码中有一个功能,可以以不同的方
我有 JRuby 代码: class Receiver def initialize(channel_id) @channel_id = channel_id factory =
Spring AMQP Reference说: Starting with version 1.3, the CachingConnectionFactory can be configured to
我以这种方式使用rabbitTemplate: localhost 发送至交易所: rabbitTemplate.setExch
从 this question 开始,我们有一个 Rabbit 凭证失效的场景,我们需要在我们的 CachingConnectionFactory 上调用 resetConnection() 来获取一
我有多个模块,它们通过消息队列 (Spring Rabbit) 相互通信。一些模块产生消息,而另一些模块使用它们。但是,单个模块可以监听不同的队列,我在列表中有一个队列名称列表,因此我为每个队列名称创
spring-rabbit 可以支持单个主题上的多个并发消费者吗? 详细信息如下 我的系统使用手动确认模式,通过 spring-rabbit (Spring 4.0.6) 进行主题交换。模式如下: 消
我想并行处理来自 rabbitMq 队列的消息。队列配置为 autoAck =false。我正在使用 camel-rabbitMQ 支持 camel endpoints ,它支持 threadPool
我正在开发一个支持 rabbitmq 的应用程序。所以,我有一个消费者和一个生产者。我需要在两种方式之间做出决定,如何在它们之间建立通信。 第一种方式 public void send(){ /
我有以下监听器方法: @Override public void onMessage(Message message, Channel channel) { try { // do som
如何在给其他消费者拒绝消息或一段时间后不回复后重复发送消息?不包括当前消费者? 最佳答案 对于 RabbitMQ,您可以使用 Acknowledgements .成功处理消息后,您的消费者将确认(确认
当我在交易所发布时收到 Nack 时,我在配置 ReturnCallback 时遇到问题。这是我所做的: CachingConnectionFactory connectionFactory = ne
我们使用 RabbitMQ 服务器在应用程序之间进行消息传递。我们需要为所有进入 Rabbit 服务器的 amqp 消息创建一个中央日志。我们的目的不是临时调试,而是可审计性。理想情况下,我可以先登录
RabbitMQ 似乎占用了太多磁盘空间并且无法启动。如何在我的 Mac 上删除它?我似乎找不到它。我已经尝试删除所有图像和容器,然后从头开始重建,希望它能解决问题。 $docker logs rab
我正在尝试进行rabbitmq http api调用,以了解队列的存在方式和其他信息... 我需要3个变量才能传递给api 1)网址:(http:// localhost:55672 / api)2)
我是一名优秀的程序员,十分优秀!