I've been stuck on this one for getting on for two days now. I've used ActiveMQ before, but in a rather Ad-Hock manner using profiles set up by imqadmin and read using the fsContext stuff. Now I'm trying to do it the proper way, and am suffering for it. I'm defining a ConnectionFactory and a Topic in Tomcat's global resources, bringing them into Spring as JNDI references and, finally, using JMSTemplate to build and publish a message. All really basic.
The result I get is this JMSException which says "Transport not running". If I include a transaction manager it happens when the transaction is started, if not then it happens when I call execute on the JMSTemplate.
Here's the resource entries from GlobalNamingResoruces in server.xml
<Resource auth="Container" description="JMS Connection factory"
name="jms/ConnectionFactory" type="org.apache.activemq.ActiveMQConnectionFactory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="tcp://ccdwaretest:7676"
clientID="OCSRelay" useEmbeddedBroker="false" userName="guest" password="guest" />
<Resource name="jms/ocsTopic" auth="Container" type="org.apache.activemq.command.ActiveMQTopic" description="my Topic"
factory="org.apache.activemq.jndi.JNDIReferenceFactory" physicalName="OCS_RELAYED"/>
{code}Here's the Spring XML
{code:java}
<jee:jndi-lookup id="jmsConnectionFactory" jndi-name="jms/ConnectionFactory"
resource-ref="true" proxy-interface="javax.jms.ConnectionFactory"/>
<jee:jndi-lookup id="ocsTopic" jndi-name="jms/ocsTopic" resource-ref="true"
proxy-interface="javax.jms.Topic"/>
<bean class="com.cc.mer.publish.sms.OCSPublishSMSImpl"
p:connectionFactory-ref="jmsConnectionFactory" p:ocsTopic-ref="ocsTopic"/>
{code}And here's the class
{code:java}
@Transactional
public class OCSPublishSMSImpl implements OCSPublish {
private static final Log log = LogFactory.getLog(OCSPublishSMSImpl.class);
private ConnectionFactory connectionFactory;
private Destination ocsTopic;
public void publishOcsMessage(final String xml, final Map<String, String> properties) {
JmsTemplate template = new JmsTemplate(connectionFactory);
template.setPubSubDomain(true);
ProducerCallback process = new ProducerCallback() {
public Object doInJms(Session sn, MessageProducer mp) throws JMSException {
Message msg = sn.createTextMessage(xml);
for (Map.Entry<String, String> prop : properties.entrySet()) {
msg.setStringProperty(prop.getKey(), prop.getValue());
}
mp.send(msg);
return null;
}
};
template.execute(ocsTopic, process);
}
public void setConnectionFactory(ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
public void setOcsTopic(Topic ocsTopic) {
this.ocsTopic = ocsTopic;
}
}
{code}
This seems a pretty basic use of activemq, but I admit every example in the documentation uses an embedded broker rather than a TCP connected external one. Has anyone had similar problems and, even better, overcome them?
You can argue whether this is in the right forum if you like but since it could be caused by any of the components in the Subject, it seems sensible to put it in a central one.
(It doesn't help that the words from "Transport not running" are useless as search terms).
Edited by: malcolmmc on Jun 22, 2010 9:35 AM