大家!

我正在尝试对ActiveMQ使用JDBC持久性。因此,生产者发送消息时,默认情况下应将其保存到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。

越来越少应该有一些例外

10-08 02:18