开发者

Help with Spring and JMS. I am trying to setup a simple publisher using spring?

So I have the following publisher:

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.Topic;

import org.springframework.jms.core.MessageCreator;
import org.springframework.jms.core.JmsTemplate;

public class JmsTopicSender {

    private JmsTemplate jmsTemplate;
    private Topic topic;

    public void setTopic(Topic topic) {
        this.topic = topic;
    }

    public void simpleSend() {
        this.jmsTemplate.send(this.topic, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage("hello Topic");
            }
        });
    }
}

So Im now stuck setting up the bean declarations. I know I need a JMSTemplate:

<bean id="jms-template" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connection-factory" />
    <property name="defaultDestination" ref="destination" />
</bean>

But I dont know how to set the connection factory or destination up. There isnt even an example in the sp开发者_如何学运维ring docs.


Your connection factory can be standalone:

<bean id="connection-factory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:12345"/>
</bean>

Or you can retrieve it from JNDI:

<jee:jndi-lookup id="connection-factory" jndi-name="jms/ConnFactory"/>

Same for your destination:

<bean:id="myQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="queue.my"/>
</bean>

<jee:jndi-lookup id="myQueue" jndi-name="jms/MyQueue"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜