【发布时间】:2021-07-17 19:15:06
【问题描述】:
我目前已经像这样配置了我的 Tomcat 的 context.xml:
<Resource name="jms/ConnectionFactory" auth="Container" type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS Connection Factory" factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="tcp://MY_LOCALHOST_URL:7270" brokerName="LocalActiveMQBroker" useEmbeddedBroker="false"/>
<Resource name="AppJms-HVDIVD17CA50359" auth="Container" type="org.apache.activemq.ActiveMQConnectionFactory" factory="org.apache.activemq.jndi.JNDIReferenceFactory" physicalName="APP.QUEUE" />
我有我的activemq.xml:
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="appjms" uri="tcp://MY_LOCALHOST_URL:7270?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
我正在像这样在 Java 代码中启动 JMS:
public void createMessageSubscriberJms(String host, int port, String jmsDestination) throws JMSException, UnknownHostException {
String hostname = InetAddress.getLocalHost().getCanonicalHostName();
String providerEndpoints = "tcp://" + hostname + ":" + port + "?wireFormat.maxInactivityDuration=7200000";
// Set the trusted packages/classes to move back and forth on the ActiveMQ JMS service.
ArrayList<String> trustedClasses = new ArrayList<String>();
trustedClasses.add("com.gtt.common.shared.GTCMessage");
// Obtain the factory
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(providerEndpoints);
// Add the trusted packages/classes to the ActiveMQ consumer.
//activeMQConnectionFactory.setTrustedPackages(trustedClasses);
activeMQConnectionFactory.setTrustAllPackages(true);
//Create the connection
setQueueConnection(activeMQConnectionFactory.createQueueConnection());
getQueueConnection().setClientID(this.getName());
// Make a session
setSession(getQueueConnection().createQueueSession(false, Session.AUTO_ACKNOWLEDGE));
getSession().createQueue(jmsDestination);
// Create the destination
Destination destination = getSession().createQueue(jmsDestination);
String selector = "JMSCorrelationID = '" + getActionRequest().getOriginId() + "_" + getActionRequest().getRequestId() + "'" ;
setConsumer(getSession().createConsumer(destination, selector));
getConsumer().setMessageListener(new DefaultMessageListener(this));
// Start ...
// We'll need a message store now
gtcMessages = new GTCMessageQueue<GTCMessage>();
getQueueConnection().start();
}
但是当我启动 Tomcat 并调用该方法时,我收到以下错误:
Name [AppJms-HVDIVD17CA50359] is not bound in this Context. Unable to find [AppJms-HVDIVD17CA50359].
你能告诉我我做错了什么吗?我确信当我使用旧版本的 Tomcat 和 ActiveMQ 时,相同的配置也可以工作。
目前我使用的是 Tomcat 9.0.45 和 ActiveMQ 5.16.1。
【问题讨论】:
标签: java tomcat jms activemq tomcat9