weblogic下配置jms步骤:
一.先配置持久化存储:
1.服务>jdbc>持久化存储
选择filestore,然后如下:
如上配置持久化名称,制定持久化目录。
二.配置JMS服务器
1.服务-消息传递-JMS服务器-选择新建
2.JMS服务器的名臣可以默认,也可以自行设置,持久化存储选择你刚才创建的持久化名称。
3.单击下一步,选择目标:AdminServer
4.这就完成JMS服务器的配置。
三.配置JMS模块
1.服务-消息传送-JMS模块-点击新建
2.模块名称可以默认,也可以自行设置,点击下一步,选择你刚才创建的JMS服务器:
3.点击下一步,完成。
四.配置子部署:
1.点击 服务-消息传送-JMS模块-点击进去你刚才创建的模块-选择子部署:
2.选择新建-设置子部署的名称-下一步-选择子部署的目标服务器,选择你刚才创建的服务器
注意不要选AdminServer。
3.点击完成,如图子部署成功
五.创建队列
1. 点击 服务-消息传送-JMS模块-点击进去你刚才创建的JMS模块,选择新建-队列:
2.点击下一步,设置JMS目标属性:
名称可以默认,但是JNDI必须唯一,因为在创建项目时,需要根据JNDI查找消息目的
3.点击下一步,选择你刚才创建的子部署
4.点击完成。
六.创建工厂
1.点击 服务-消息传送-JMS模块-点击进去你刚才创建的JMS模块,选择新建-连接工厂-下一步-设置工厂名称和JNDI名(唯一)
2.点击下一步,完成。
通过上述步骤就完成了PTP的JMS服务器的全部配置。
(不懂得步骤的可以留言,我尽量帮你,希望给我分啊!)
一.先配置持久化存储:
1.服务>jdbc>持久化存储
选择filestore,然后如下:
如上配置持久化名称,制定持久化目录。
二.配置JMS服务器
1.服务-消息传递-JMS服务器-选择新建
2.JMS服务器的名臣可以默认,也可以自行设置,持久化存储选择你刚才创建的持久化名称。
3.单击下一步,选择目标:AdminServer
4.这就完成JMS服务器的配置。
三.配置JMS模块
1.服务-消息传送-JMS模块-点击新建
2.模块名称可以默认,也可以自行设置,点击下一步,选择你刚才创建的JMS服务器:
3.点击下一步,完成。
四.配置子部署:
1.点击 服务-消息传送-JMS模块-点击进去你刚才创建的模块-选择子部署:
2.选择新建-设置子部署的名称-下一步-选择子部署的目标服务器,选择你刚才创建的服务器
注意不要选AdminServer。
3.点击完成,如图子部署成功
五.创建队列
1. 点击 服务-消息传送-JMS模块-点击进去你刚才创建的JMS模块,选择新建-队列:
2.点击下一步,设置JMS目标属性:
名称可以默认,但是JNDI必须唯一,因为在创建项目时,需要根据JNDI查找消息目的
3.点击下一步,选择你刚才创建的子部署
4.点击完成。
六.创建工厂
1.点击 服务-消息传送-JMS模块-点击进去你刚才创建的JMS模块,选择新建-连接工厂-下一步-设置工厂名称和JNDI名(唯一)
2.点击下一步,完成。
通过上述步骤就完成了PTP的JMS服务器的全部配置。
(不懂得步骤的可以留言,我尽量帮你,希望给我分啊!)
public static void main(String[] args) {
try {
Properties p = new Properties();
p.put("Context.INITIAL_CONTEXT_FACTORY","weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7003");;
p.put(Context.SECURITY_PRINCIPAL,"weblogic");
p.put(Context.SECURITY_CREDENTIALS,"weblogic");
Context ctx = new InitialContext(p);
ctx.bind("name","zs");
Object ojbObject = ctx.lookup("name");
System.out.println(ojbObject.toString());
QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup("testcf");//ConnectionFactory-0
QueueConnection qConnection = connectionFactory.createQueueConnection();
QueueSession qSession = qConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup("testjms");
// 消息发送者
QueueSender qSender = null;
// 会话
//根据队列建立消息发送者
qSender = qSession.createSender(queue);
//建立消息
// ObjectMessage objectMessage = qSession.createObjectMessage();
TextMessage tesTextMessage= qSession.createTextMessage();
qSession.createTextMessage();
//开始连接
qConnection.start();
tesTextMessage.setText("hello 你好");
//开始发送消息
qSender.setDeliveryMode(DeliveryMode.PERSISTENT);
qSender.send(tesTextMessage);
} catch (NamingException e) {
e.printStackTrace();
} catch (JMSException e) {
e.printStackTrace();
}
}}报一个异常:zs
javax.naming.NameNotFoundException: Exception in lookup.: `testcf' could not be found. [Root exception is weblogic.corba.cos.naming.NamingContextAnyPackage.NotFound: IDL:weblogic/corba/cos/naming/NamingContextAny/NotFound:1.0]
at weblogic.corba.j2ee.naming.Utils.wrapNamingException(Utils.java:65)
at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:230)
at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:168)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.jms.test.JmsTest.main(JmsTest.java:34)
Caused by: weblogic.corba.cos.naming.NamingContextAnyPackage.NotFound: IDL:weblogic/corba/cos/naming/NamingContextAny/NotFound:1.0
at weblogic.corba.cos.naming.NamingContextAnyPackage.NotFoundHelper.read(NotFoundHelper.java:72)
at weblogic.corba.cos.naming._NamingContextAnyStub.resolve_any(_NamingContextAnyStub.java:87)
at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:208)
... 3 more
JDNI 找不到JMS 的联连工厂,帮我看看 那有问题 。谢谢了。
我想接收一下,代码如下 MessageConsumer comsumer = qSession.createConsumer(queue);
Message recvMessage = comsumer.receive();
System.out.println(((TextMessage)recvMessage).getText());
/**
comsumer.setMessageListener(new MessageListener(){ public void onMessage(Message message) {
TextMessage textMessage = (TextMessage)message;
try {
System.out.println(textMessage.getText());
} catch (JMSException e) {
e.printStackTrace();
}
}
});**/上边的代码和发送的部分代码相同。只是接收的时候,能看到有使用数据在增加,但没有输出消息信息。
报一个空指针异常。zs
java.lang.NullPointerException
at com.jms.test.JmsReceiveTest.main(JmsReceiveTest.java:44)
今天测试put/sub 发送成功了。但是在weblogic 里找不到这条消息。代码如下:public class JmsSenderTopicTest {
private static TopicConnection tConnection=null;
public static void main(String[] args) {
try {
Properties p = new Properties();
p.put("Context.INITIAL_CONTEXT_FACTORY","weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7003");;
p.put(Context.SECURITY_PRINCIPAL,"weblogic");
p.put(Context.SECURITY_CREDENTIALS,"weblogic");
Context ctx = new InitialContext(p);
/**测试JNDI 是否联连成功 是否可以把属性挂在JNDI 树上 开始*/
ctx.bind("name","zs");
Object ojbObject = ctx.lookup("name");
System.out.println(ojbObject.toString());
/**测试JNDI 是否联连成功 是否可以把属性挂在JNDI 树上 结束*/
TopicConnectionFactory connectionFactory = (TopicConnectionFactory) ctx.lookup("testcf");//ConnectionFactory-0
tConnection = connectionFactory.createTopicConnection();
TopicSession tSession = tConnection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) ctx.lookup("testTopic");
// 消息发送者
TopicPublisher tPublisher = null;
// 会话
//根据队列建立消息发送者
tPublisher = tSession.createPublisher(topic);
/***发送text 文本信息 开始**/
//建立消息
TextMessage tesTextMessage= tSession.createTextMessage();
tSession.createTextMessage();
//开始连接
tConnection.start();
tesTextMessage.setText(" 哈哈 成功了3");
//开始发送消息
tPublisher.setDeliveryMode(DeliveryMode.PERSISTENT);
tPublisher.send(tesTextMessage);
/***发送text 文本信息 结束**/
/***发送Object 自定义对象信息 开始
ObjectMessage objectMessage=qSession.createObjectMessage(Student.class);
qSession.createObjectMessage();
qConnection.start();
objectMessage.setObject(new Student(1,"张三",19,98.0));
qSender.setDeliveryMode(DeliveryMode.PERSISTENT);
qSender.send(objectMessage);
/***发送Object 自定义对象信息 结束**/
System.out.println("发送完毕");
} catch (NamingException e) {
e.printStackTrace();
} catch (JMSException e) {
e.printStackTrace();
}finally{
try {
if(tConnection != null){
tConnection.close();
}
} catch (JMSException e) {
e.printStackTrace();
}
}
}}