站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2EE 专题600分,关于Sun Application Server的jms访问!

600分,关于Sun Application Server的jms访问!

摘要: 600分,关于Sun Application Server的jms访问!


各位高手:

我在Sun Application Server配置jms的ConnectionFactory,queue等,但我不知道怎么通过client远程访问jms?
上网google了一下,发现有很多写法:

第一种:
env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://192.168.1.168:3700");
ctx = new InitialContext(env);
qcf = (javax.jms.QueueConnectionFactory) ctx.lookup("MyQueueConnectionFactory");


第二种:
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
env.put(Context.PROVIDER_URL, ""mq://10.167.16.31:7676"")


第三种:
System.setProperty("com.sun.jndi.ldap.LdapCtxFactory", "iiop://localhost:3700");


第四种:
props.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
props.put("java.naming.provider.url", "iiop://localhost:3700");


第五种:
props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.enterprise.naming.SerialInitContextFactory");
props.put(Context.PROVIDER_URL,"iiop://serverIP:3700");


我在sun的网站上也没有找到标准的写法,各位高手,你们一般是怎么写的?






其实我的需求很简单,就是怎么通过jms client远程访问sun message queue?


一般需要put进Context.INITIAL_CONTEXT_FACTORY和Context.PROVIDER_URL属性就可以了
你上面列举的几个Context.INITIAL_CONTEXT_FACTORY类名,你先要确定你的lib库中是否有这个类.还有Context.PROVIDER_URL里面端口也需要确定那个端口是否打开.具体Sun Application Server用那个类,先要确定你的JMS server是用那个产品的.是Sun Application Server自带的?


楼上的兄弟,我测试了不行啊!

倒是下面这样写是可以的:
String host = "10.167.16.201"; //server machine IP
String port = "3700"; //port
System.setProperty("org.omg.CORBA.ORBInitialHost", host);
System.setProperty("org.omg.CORBA.ORBInitialPort", port);
ctx = new InitialContext();

哪位高手能不能详细的讲解一下它们的区别?


Properties prop = new Properties();

prop.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
prop.put(Context.PROVIDER_URL,"iiop://localhost:7676");

JndiTemplate jndi = new JndiTemplate(prop);
QueueConnectionFactory fabrika = (QueueConnectionFactory) jndi.lookup("qcf");


哦,理论上是应该可以的,因为我以前用这种方式连过Jboss自带的jms,也连过IBM的MQ.
帮楼主顶!


To c366oem(zoey) :

我用的就是Sun Application Server自带的message queue,但我是在Sun Application Server中配置的ConnectionFactory等。


本来我是单独安装了sun message queue,但它的example都是本地测试的,我不知道怎么远程测试(远程测试需要jndi server),所以就干脆用Sun Application Server自带的sun message queue


to c366oem(zoey) :

你上面的写的localhost,而且RefFSContextFactory是文件系统的,好象还需要指定一个目录。

如果在另外一台机器运行jms client,肯定是不行了。


各位高手,请教2个问题:

1:远程的jms client怎么通过SSL进行访问sun message queue?

2:大家一般都是怎么集群的?


up


com.sun.messaging.QueueConnectionFactory 类的方法
setProperty("imqAddressList","10.0.65.11:7676,10.0.65.11:7777");

1、这个是直接通过com.sun.messaging.QueueConnectionFactory 创建连接--这个很简单

2、也可以采用

com.sun.jndi.fscontext.RefFSContextFactory 文件系统环境工厂来配置一个连接到messagequeue 的环境。然后通过

Properties prop = new Properties();

prop.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
prop.put(Context.PROVIDER_URL,"file:///c:/mytest");

再用jndi 来获取messagequeue Server上面的 QueueConnectionFactory对象

然后通过QueueConnectionFactory 对象来创建连接

如何初始化一个绑定的对象文件上下文环境系统呢?
可以通过sun messagequeue 自带的可执行文件,可以生成这个文件系统环境上下文
c:/mytest




单个 setProperty("imqAddressList","10.0.65.11:7676");



还有其他参数,你可以自己去探索一下,^_^


其实,你的这些问题,我相信在这里的文档都能告诉你:
http://docs.sun.com/app/docs/prod/s1msgqu?l=zh#hic


Sun产品系列命名太怪了,好多版本,而且一个产品又包含若干个产品。




csrcom(泥鳅)兄,你好!

你说的用com.sun.jndi.fscontext.RefFSContextFactory 文件系统环境工厂来配置一个连接到messagequeue 的环境,再用jndi 来获取messagequeue Server上面的 QueueConnectionFactory对象。

请教,这种方式能远程通过jndi来获取QueueConnectionFactory吗?



首先你要在server端 创建一个 QueueConnectionFactory (用imqobjmgr 工具,只要安装了message queue 就有了)。

相关这方面的demo: MessageQueue安装路径下面/demo/imqobjmgr


csrcom(泥鳅)兄:
我是用imqadmin进行了配置,参考http://docs.sun.com/source/819-3561/quick-start.html做的,在本机测试是可以的,但远程就不行。

正如上面你写的prop.put(Context.PROVIDER_URL,"file:///c:/mytest"); 这个PROVIDER_URL都指向本地的文件系统,怎么可能支持远程jms client?


csrcom(泥鳅)兄:

本来我是单独的只安装了sun message queue,但好象要远程的发消息的话,必须要再安装一个jndi server(如:openldap之类的)。

是这样的吗?难道sun message queue本身没有jndi服务吗?难道不支持远程发消息吗?

我不知道怎么做,请csrcom(泥鳅)兄不吝指教,谢谢!






所以我干脆就用Sun Application Server,因为Sun Application Server自带了sun message queue,而且我目前就是通过以下方式来远程发消息的:

String host = "10.167.16.201"; //server machine IP
String port = "3700"; //port
System.setProperty("org.omg.CORBA.ORBInitialHost", host);
System.setProperty("org.omg.CORBA.ORBInitialPort", port);
ctx = new InitialContext();

不知道csrcom(泥鳅)兄是怎么做的?




先顶一下, 搬条板凳
等泥鳅兄过来, 看看他得做法


1.使用JNDI查询
 

我们以在SUN Java System Application Server 8.1中添加工厂对象为例,将QueueConnectionFactory 对象绑定到jndi tree,并在属性编辑列表中添加属性“AddressList”,其值为 “mq://localhost:7676/, mq://localhost:7686/”. 
2.直接实例化工厂对象
 

import com.sun.messaging.*;
myQConnFactory = new com.sun.messaging.QueueConnectionFactory();
myQConnFactory.setProperty(ConnectionConfiguration.imqAddressList, "localhost:7676,localhost:7686");
myQConnFactory.setProperty(ConnectionConfiguration.imqAddressListBehavior, "RANDOM");


编译运行时,将imqlibjms.jar, imqlibimq.jar 加入到classpath。




csrcom(泥鳅)兄:

请继续到下面的链接指导吧,先谢谢了!

http://community.csdn.net/Expert/topic/4854/4854621.xml?temp=.1131555



本贴就快要揭贴了,各位高手继续指导啊!


↑返回目录
前一篇: JAVA 连接 MS SQL Server 2000数据库有几种方法?
后一篇: 请高手帮我看下数据库哪里出了问题,在线等 ... ...