我有一个在apache / PHP上运行的Web应用程序。在PHP中,我有一个activeMQ生成器,它将一些数据写入队列。我正在使用stomp客户端。对于消费者来说,我正在使用JMS + spring。我能用PHP编写消息(即生产者)。但是在从我的JMS消费者那里阅读时,我得到了Could not refresh JMS Connection for destination - retrying in 5000 ms. Cause: Wire format negotiation timeout: peer did not send his wire format
。
这是我的applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<context:annotation-config/>
<context:component-scan base-package="test"/>
<amq:connectionFactory id="jmsFactory" brokerURL="tcp://localhost:61613" />
<bean id="jmsConsumerConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory"
p:targetConnectionFactory-ref="jmsFactory"/>
<jms:listener-container container-type="default"
connection-factory="jmsConsumerConnectionFactory>
<jms:listener destination="/topic/event" ref="jmsMessageListener" />
</jms:listener-container>
<amq:queue id="destination" physicalName="/topic/event"/>
</beans>
这是我的消息监听器:
package test;
import javax.jms.Message;
import javax.jms.MessageListener;
import org.springframework.stereotype.Component;
@Component
public class JmsMessageListener implements MessageListener {
@Override
public void onMessage(Message message) {
System.out.println("msg recvd!");
}
}
有一个示例java程序作为apache activemq stomp示例的一部分,它可以正常工作。这是一个例子:
package example;
import org.fusesource.stomp.jms.*;
import javax.jms.*;
class Listener {
public static void main(String []args) throws JMSException {
String user = env("ACTIVEMQ_USER", "admin");
String password = env("ACTIVEMQ_PASSWORD", "password");
String host = env("ACTIVEMQ_HOST", "localhost");
int port = Integer.parseInt(env("ACTIVEMQ_PORT", "61613"));
String destination = arg(args, 0, "/topic/event");
StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
factory.setBrokerURI("tcp://" + host + ":" + port);
Connection connection = factory.createConnection(user, password);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination dest = new StompJmsDestination(destination);
MessageConsumer consumer = session.createConsumer(dest);
long start = System.currentTimeMillis();
long count = 1;
System.out.println("Waiting for messages...");
}
}
我在一个论坛中读到它,当生产者写入主题而不是队列时可能会发生这种情况。如果是这样,我怎么在春天处理它?</ p>