gpt4 book ai didi

java - ActiveMQ JDBC持久化问题: ACTIVEMQ_MSGS is always empty

转载 作者:太空宇宙 更新时间:2023-11-04 14:11:39 26 4
gpt4 key购买 nike

大家!

我正在尝试将 JDBC 持久性与 ActiveMQ 结合使用。所以,当生产者发送消息时,它应该默认保存到ACTIVEMQ_MSGS表中。但当我检查这张表时,它总是空的。我不明白问题出在哪里。

这是 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 生产者代码:

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();
}

}
}
}

最佳答案

您在连接工厂和代理传输中有不同的 url。您可能应该在两个地方都有 tcp://localhost:61616。

无论如何,应该有一些异常(exception)

关于java - ActiveMQ JDBC持久化问题: ACTIVEMQ_MSGS is always empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28252010/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com