我在使用队列消息时遇到问题。我已经定义了一个监听器但由于某种原因我无法使用任何消息。我在onMessage函数中添加了断点,但它们永远不会被击中。这是我的代码文件。不确定这里有什么问题:
配置文件:
<rabbit:connection-factory id="emailAccountConnectionFactory" host="localhost"/>
<rabbit:template id="amqpTemplate" connection-factory="emailAccountConnectionFactory"
exchange="emailAccountExchange" routing-key="email.Account"/>
<!-- <rabbit:admin connection-factory="emailAccountConnectionFactory" />-->
<rabbit:queue id="emailAccount" name="emailAccountQueue"/>
<rabbit:direct-exchange name="emailAccountExchange">
<rabbit:bindings>
<rabbit:binding queue="emailAccount" key="email.Account" />
</rabbit:bindings>
</rabbit:direct-exchange>
<rabbit:listener-container connection-factory="emailAccountConnectionFactory" acknowledge="none">
<rabbit:listener ref="emailAccountAckListener" queue-names="emailAccountQueue" />
</rabbit:listener-container>
<bean id="emailAccountAckListener" class="start.web.listener.registration.EmailAccountAckListener" />
Message Listener类:
package start.web.listener.registration;
import java.util.Map;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.stereotype.Component;
import start.web.common.EventHandler;
import start.web.common.Events;
@Component
public class EmailAccountAckListener implements MessageListener {
public void onMessage(Message message) {
System.out.print("Message Received");
EventHandler.handler((Events) ((Map<String, Object>)
message).get("event"), ((Map<String, Object>)
message).get("message"));
}
}
我无法在onMessage函数中命中断点。同样在RabbitMQ的管理控制台上,我看不到任何消费者的队列。我不确定我在配置中做错了什么。以下是队列管理控制台的屏幕截图: