There is an application based on Spring 3.0.5 framework running on JBoss 5.1 server.
I tried to follow this tutorial, but it uses the ActiveMQ broker instead of JBossMQ (default JBoss 5.1 broker).
I've already set a queue called MyQueue in JBoss config (destinations-service.xml):
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.messaging.destination:service=Queue,name=MyQueue"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
You can see the rest of my config below. What am I missing? How can I specify the JNDI name of the queue and the connection factory? And what about the server address ([ConnectionFactory] Connector bisocket://localhost:4457)?
My config in applicationContext.xml is as follow:
<bean id="connectionFactory" class="org.jboss.jms.server.connectionfactory.ConnectionFactory" />
<bean id="messageDestination" class="javax.jms.Queue" />
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="receiveTimeout" value="10000" />
</bean>
<bean id="springJmsProducer" class="myPackage.QueueProducer">
<property name="destination" ref="messageDestination" />
<property name="jmsTemplate" ref="jmsTemplate" />
</bean>
<bean id="messageListener" class="myPackage.QueueConsumer" />
My Producer:
public class QueueProducer {
private JmsTemplate jmsTemplate;
private Queue queue;
public void setConnectionFactory(ConnectionFactory cf) {
this.jmsTemplate = new JmsTemplate(cf);
}
public void setQueue(Queue queue) {
this.queue = queue;
}
public void send(Object object) {
this.jmsTemplate.send(this.queue, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("my text to send");
}
});
}
}
My Consumer:
public class QueueConsumer implements MessageListener {
@Override
public void onMessage(Message message) {
if (message instanceof TextMessage) {
try {
System.out.println(((TextMessage) message).getText());
}catch (JMSException ex) {
throw new RuntimeException(ex);
}
}
else {
throw new IllegalArgumentException("Message must be of type TextMessage");
}
}
}