[原创]weblogic,jms_Tomcat, WebLogic及J2EE讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Tomcat, WebLogic及J2EE讨论区 »
总帖数
4
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 5067 | 回复: 3   主题: [原创]weblogic,jms        下一篇 
jinzhu.tian
注册用户
等级:上尉
经验:502
发帖:12
精华:0
注册:1970-1-1
状态:离线
发送短消息息给jinzhu.tian 加好友    发送短消息息给jinzhu.tian 发消息
发表于: IP:您无权察看 2014-7-22 16:29:21 | [全部帖] [楼主帖] 楼主

JMS有2种模式,Point-to-Point和Publish/Subscribe。在weblogic下部署jms,我们需要先进行配置,具体过程不再详述。一般配置成功后可以再jndi树中看到配置信息,如下图:

                    图-1 jms工厂、队列

图-2 jndi树

点对点模式:

发送消息前队列:

发送消息:

发送后队列:



  • 本版精华
  • 热门帖子

  • 赞(0)    操作        顶端 
    jinzhu.tian
    注册用户
    等级:上尉
    经验:502
    发帖:12
    精华:0
    注册:1970-1-1
    状态:离线
    发送短消息息给jinzhu.tian 加好友    发送短消息息给jinzhu.tian 发消息
    发表于: IP:您无权察看 2014-7-22 16:36:13 | [全部帖] [楼主帖] 2  楼

    图传不上来?

    北京联动北方科技有限公司

                        图-1 jms工厂、队列

    北京联动北方科技有限公司

    图-2 jndi树



    赞(0)    操作        顶端 
    jinzhu.tian
    注册用户
    等级:上尉
    经验:502
    发帖:12
    精华:0
    注册:1970-1-1
    状态:离线
    发送短消息息给jinzhu.tian 加好友    发送短消息息给jinzhu.tian 发消息
    发表于: IP:您无权察看 2014-7-22 16:40:25 | [全部帖] [楼主帖] 3  楼

    代码如下:

    生产者:

    public class Sender {
          public void send(){
                BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
                String icf="weblogic.jndi.WLInitialContextFactory";
                String url="t3://localhost:7001";
                Hashtable env = new Hashtable();
                env.put(Context.INITIAL_CONTEXT_FACTORY,icf);
                env.put(Context.PROVIDER_URL,url);
                try{
                      final InitialContext initContext= new InitialContext(env);
                      QueueConnectionFactory factory= (QueueConnectionFactory)initContext.lookup("myfactory");
                      Queue destination = (Queue)initContext.lookup("myqueue");
                      initContext.close();
                      QueueConnection connection = factory.createQueueConnection();
                      QueueSession session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
                      QueueSender sender = session.createSender(destination);
                      String messageText=null;
                      while(true){
                            System.out.println("Enter message to send or 'quit':");
                            messageText = reader.readLine();
                            if("quit".equals(messageText))
                            break;
                            TextMessage message = session.createTextMessage(messageText);
                            sender.send(message);
                      }
                      System.out.println("Exiting...");
                      reader.close();
                      connection.close();
                      System.out.println("Goodbye!");
                }catch(Exception e){
                e.printStackTrace();
                System.exit(1);
          }
    }
    public static void main(String[] args){
          (new Sender()).send();
    }
    }


    消费者:

    public class Receiver implements MessageListener {
          private boolean stop=false;
          public static void main(String[] args){
                (new Receiver()).receive();
          }
          public void receive() {
                String icf = "weblogic.jndi.WLInitialContextFactory";
                String url="t3://localhost:7001";
                // Initialise JNDI properties
                Hashtable env = new Hashtable();
                env.put( Context.INITIAL_CONTEXT_FACTORY, icf );
                env.put( Context.PROVIDER_URL, url );
                try{
                      //Look up administratered objects
                      final InitialContext initContext = new InitialContext(env);
                      QueueConnectionFactory factory = (QueueConnectionFactory) initContext.lookup("myfactory");
                      Queue destination = (Queue) initContext.lookup("myqueue");
                      initContext.close();
                      //Create JMS objects
                      QueueConnection connection = factory.createQueueConnection();
                      QueueSession session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
                      QueueReceiver receiver= session.createReceiver(destination);
                      receiver.setMessageListener(this);
                      connection.start();
                      System.out.println("服务启动");
                      while(!stop){
                            Thread.sleep(1000);
                      }
                      //Exit
                      System.out.println("Exiting...");
                      connection.close();
                      System.out.println("Goodbye!");
                }catch(Exception e){
                e.printStackTrace();
                System.exit(1);
          }
    }
    public void onMessage(Message message) {
          // TODO Auto-generated method stub
          try {
                String msgText = ((TextMessage)message).getText();
                System.out.println(msgText);
                if("stop".equals(msgText)){
                      stop = true;
                }
          } catch (JMSException e) {
                e.printStackTrace();
                stop = true;
          }
    }
    }



    赞(0)    操作        顶端 
    jinzhu.tian
    注册用户
    等级:上尉
    经验:502
    发帖:12
    精华:0
    注册:1970-1-1
    状态:离线
    发送短消息息给jinzhu.tian 加好友    发送短消息息给jinzhu.tian 发消息
    发表于: IP:您无权察看 2014-7-22 17:06:12 | [全部帖] [楼主帖] 4  楼

    几个bug:

    javax.naming.NameNotFoundException: Unable to resolve 'myfactory'. Resolved '' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'myfactory'. Resolved '']; remaining name 'myfactory'


    查了很多资料,这个bug是Weblogic System Libraries包引起的,将Weblogic System Libraries删除,然后添加需要的包,bug解除,然后出现了新的bug

    com.sun.corba.se.impl.encoding.CDRInputStream_1_0 read_value


    警告: "IOP00810211: (MARSHAL) Exception from readValue on ValueHandler in CDRInputStream"

    org.omg.CORBA.MARSHAL:   vmcid: SUN  minor code: 211 completed: Maybe


    又导入一些包后解决,接着又有bug

    com.sun.corba.se.impl.encoding.CDRInputStream_1_0 read_value


    警告: "IOP00810211: (MARSHAL) Exception from readValue on ValueHandler in CDRInputStream"

    换了weblogic的jdk后解决。



    赞(0)    操作        顶端 
    总帖数
    4
    每页帖数
    101/1页1
    返回列表
    发新帖子
    请输入验证码: 点击刷新验证码
    您需要登录后才可以回帖 登录 | 注册
    技术讨论