随笔:一个单独的JMS例程
来源:互联网 发布:图片特效制作软件 编辑:程序博客网 时间:2024/05/16 01:33
开发工具:WebSphere Integration Developer 6.1(WID)
中间件服务器: WebSphere Process Server (WPS)
1. 在wid中创建一J2EE工程,加入一个动态web项目
2.创建index.jsp,内容如下:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="javax.jms.*" %>
<%@ page import="javax.naming.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<%
try
{
final InitialContext context = new InitialContext();
//final InitialContext context = new InitialContext(props);
// Lookup the queue connection factory from the
// initial context.
final QueueConnectionFactory qcf = (QueueConnectionFactory) context.lookup("ladqcf");
System.out.println("the qcf is "+qcf);
// Create a new queue connection from the queue
// connection factory.
final QueueConnection conn = qcf.createQueueConnection();
System.out.println("the conn is "+conn);
// Start the connection
conn.start();
// Create a new queue session from the queue
// connection. The session should not be transacted
// and should use automatic message acknowledgement.
final QueueSession qsession = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// Lookup the queue to be used to send and receive
// messages from the initial context.
final Queue q = (Queue) context.lookup("ladq");
// Create a new queue sender using the queue session.
// The sender should be created to send messages to
// the queue q.
final QueueSender sender = qsession.createSender(q);
// Create a text message using the queue session.
// Initialize the message's data to a String of your
// choice.
final TextMessage sentMessage = qsession.createTextMessage("My first JMS message.");
System.out.println("sending message : "+sentMessage.getText());
// Send the sentMessage object using the queue sender.
sender.send(sentMessage);
System.out.println("sent message : "+sentMessage.getText());
// Create a new queue receiver using the queue session.
// The queue receiver should be created to receive
// messages from the queue q.
final QueueReceiver receiver = qsession.createReceiver(q);
// Use the queue receiver to receive the message that
// was sent previously.
final Message receivedMessage = receiver.receiveNoWait();
// Output the received message to System.out
if(receivedMessage!=null)
{
System.out.println("Received Message is : "+((TextMessage)receivedMessage).getText());
}else{
System.err.println("Received nothing................");
}
}
catch (NamingException ne)
{
ne.printStackTrace();
}
catch (JMSException jmse)
{
System.err.println("error................");
Exception linkedException = jmse.getLinkedException();
if (linkedException != null)
{
linkedException.printStackTrace();
}
jmse.printStackTrace();
}
%>
</body>
</html>
3.在WPS中配置JMS资源.
a.创建BUS.登陆WPS,"Service integration"->"Buses"->"New",只要BUS的名字即可
b.添加Bus member,"Service integration"->"Buses",点击刚建立的Bus,在"Topology "下点击"Bus members",进入"Bus members"页面,点击"Add"按钮. step1, 选择server项; step2,选择filestore; step3 默认; step4 finish. 保存配置.
c.创建Destinations. ,"Service integration"->"Buses",点击刚建立的Bus,"Destination resources"->"Destinations",
已经存在两个默认的destination, 再建立一个,点击"New" 按钮,选择类型,默认为Queue,输入Identifier ,选择所属于的Bus Member,下一步,保存.
d.创建Queue connection factory. "Resources"->"jms"->"Queue connection factory",点击"New"按钮,选择"Default messaging provider",OK进入下一页面,输入name,JNDI name填ladqcf,bus member选择刚创建的bus,其他默认,保存.
e.创建Queue."Resources"->"jms"->"Queues",点击"New"按钮,选择"Default messaging provider",OK进入下一页面,输入name,JNDI name填ladq,bus member选择刚创建的bus,Queue name选c步创建的destination,其他默认,保存.
JMS资源配置完毕.访问页面,可以看到输出.
- 随笔:一个单独的JMS例程
- ACM随笔----- 计蒜客 单独的数字
- 【Java.JMS】一个简单的JMS实例
- 【Java.JMS】一个简单的JMS实例
- Using使用的一个例程
- 一个简单的openGL例程
- opencv的一个神经网络例程
- 面向对象的一个例程
- 一个简单的入门例程
- Contiki的一个demo例程
- 将分页作为一个单独的控件
- 将分页作为一个单独的控件
- 单独一个产品销售的Magento站点
- 单独一个列表框的应用
- mysql 单独导入一个表的方法
- 一个单独的条形码扫描功能实现
- Android 单独的一个购物车
- 一个hibernate的总结性随笔
- 程序员修炼之道 读书笔记 2
- 编写firefox 扩展的文章
- Window XP 安装盘 -- 无人职守自动安装
- 数据库内连接、外连接、交叉连接
- Oracle入门(一)
- 随笔:一个单独的JMS例程
- js刷新页面
- Arcengine92升级sp3后提示 版本高于所引用的程序集
- CString 操作指南
- 深入剖析PE文件
- arcgis engine runtime错误
- JS表单判断函数代码大全
- 八种和电脑相关的易发病
- 英文主要搜索引擎及目录