[英]ActiveMQ JDBC persistence trouble: ACTIVEMQ_MSGS is always empty
everybody! 大家好!
I'm trying to use JDBC persistence with ActiveMQ. 我正在尝试对ActiveMQ使用JDBC持久性。 So, when producer sends message, it should be saved into ACTIVEMQ_MSGS table by default. 因此,生产者发送消息时,默认情况下应将其保存到ACTIVEMQ_MSGS表中。 But when I check this table, it's always empty. 但是当我检查此表时,它总是空的。 I don't understand where the trouble is. 我不知道麻烦在哪里。
Here is Spring XML config 这是Spring XML配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd
" >
<bean
id="producer"
class="com.jmsexamples.Producer">
<property name="connectionFactory" ref="jmsFactory" />
</bean>
<bean id="jdbc_ds"
class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/ActiveMq?relaxAutoCommit=true" />
<property name="user" value="root" />
<property name="password" value="" />
</bean>
<amq:connectionFactory id="jmsFactory" brokerURL="tcp://localhost:61616" />
<amq:queue id="queue" physicalName="message.queue" />
<amq:broker useJmx="false" persistent="true">
<amq:persistenceAdapter>
<amq:jdbcPersistenceAdapter dataSource="#jdbc_ds"/>
</amq:persistenceAdapter>
<amq:transportConnectors>
<amq:transportConnector uri="vm://localhost:61616" />
</amq:transportConnectors>
</amq:broker>
UPD producer code: UPD生产者代码:
public class Producer{
private ConnectionFactory connectionFactory;
private Destination dest;
public void setConnectionFactory(ConnectionFactory conFact){
this.connectionFactory = conFact;
}
public void sendMessage(){
Connection connection = null;
Session session = null;
try {
connection = connectionFactory.createConnection("roman", "sawawluha");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
dest = new ActiveMQQueue("message.queue");
MessageProducer producer = session.createProducer(dest);
for(int i=0;i<10; i++)
{
TextMessage message = session.createTextMessage();
message.setText("This is text message!");
producer.send(message);
}
} catch(JMSException e)
{
e.printStackTrace();
} finally
{
try {
session.close();
connection.close();
System.out.println("closing");
} catch(Exception e)
{
e.printStackTrace();
}
}
}
}
You have a different url in the connection factory and the broker transport. 连接工厂和代理传输中的URL不同。 You should probably have tcp://localhost:61616 at both places. 您可能在两个地方都应该有tcp:// localhost:61616。
There should be some exception around non the less 越来越少应该有一些例外
Well, as Petter said that JDBC broker is idle, I've simply restarted Fuse, changed URL's to tcp://localhost:61616, and now my producer uses correct broker. 好了,正如Petter所说的JDBC代理处于空闲状态,我只是重新启动了Fuse,将URL更改为tcp:// localhost:61616,现在我的生产者使用了正确的代理。 Thanks! 谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.