項目環境
JDK
ActiveMQ
所用的包都是ActiveMQ自帶的
package stujms
import orgntext
import orgntext
import org
import org
import javax
import javax
import javax
import javax
/**
* 消息發送者
*
* @author leizhimin
*/
public class MySender {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
JmsTemplate template = (JmsTemplate) ctx
Destination destination = (Destination) ctx
template
public Message createMessage(Session session) throws JMSException {
return session
}
});
System
}
}
package stujms
import orgntext
import orgntext
import org
import javax
import javax
import javax
/**
* 消息接收者
*
* @author leizhimin
*/
public class MyReceiver {
public static void main(String[] args) throws JMSException {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
JmsTemplate template = (JmsTemplate) ctx
Destination destination = (Destination) ctx
while (true) {
TextMessage txtmsg = (TextMessage) template
if (null != txtmsg)
System
else
break;
}
}
}
<?xml version=
<beans xmlns=
xmlns:context=
xsi:schemaLocation=
<!
<bean id=
<property name=
</bean>
<!
<bean id=
<property name=
</bean>
<!
<bean id=
<!
<constructor
</bean>
</beans>
運行發送端三次
成功發送了一條JMS消息
Process finished with exit code
然後再運行接收端一次
收到消息內容為: 發送消息
收到消息內容為: 發送消息
收到消息內容為: 發送消息
繼續測試發現
發一張圖看看
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28780.html