热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

weblogic7JMS开发,两种连接工厂都试了,topicproducer已经将消息发布至主题,但同步接收者接受不到,高手请教

我用的weblogic7开发,有两种情况:1。用的是weblogic标准的JMSConnectionFactory,编写的topicproducer已经发布成功(console已经按照输出
我用的weblogic7开发,有两种情况:
1。用的是weblogic标准的JMS ConnectionFactory,
编写的topic producer已经发布成功(console已经按照输出成功信息),但指定存放消息的目录并没有文件,运行同步消费者接收,没有任何提示和输出,也没有报错,好像一直在run,断掉weblogic server才停止。
2。用的试自己配的一个连接工厂和目录,用jb8集成weblogic7开发,用的Message-Driven Bean实现,deploy成功, 采用run as defaults,发布消息也成功,运行同步消费者接收bean时,一步一步的提示输出都已经输出,譬如:
start to receive
subscriber is created
connection  started
但到输出接收的消息仍然没有反应,一直在run
部分代码: 
   ...
   log("start to receive");//log 等同于system.out.println()

    subscriber=session.createSubscriber(newTopic);

    log("subscriber is created");

    m_topicConnection.start();

    log("connection started");
    //if synchronization

      TextMessage msg = (TextMessage) subscriber.receive();

      log("Received" + msg.getText());

      msg = (TextMessage) subscriber.receive();

      log("Received" + msg.getText());
 抛异常也试过,结果没变

高手指教啊,郁闷中

15 个解决方案

#1


第二个 消息显示在weblogic的控制台


http://expert.csdn.net/Expert/topic/1657/1657269.xml?temp=.6064264
http://expert.csdn.net/Expert/topic/1607/1607909.xml?temp=.2608454

#2


第二种情况我是直接点击JB8里面的“runing as default”,jb8窗口下放不就应该输出吗?
在console里面我也找过,好像没有啊?请告我在console那个里面

#3


我也遇到过 开始以为是程序错误 后来在weblogic的控制台看见了消息内容 就是那个dos窗口 仔细找找 可能夹在两行异常信息中间 

TextMessage msg = (TextMessage) subscriber.receive(); 不知道是否正确onMessage方法 改为如下试试

public void onMessage(Message message) {
    String msgText = "";
    String msgID = "";
    try {
      msgID = message.getJMSMessageID();
      if (message instanceof TextMessage) {
        msgText = ( (TextMessage) message).getText();
      }
      else {
        msgText = message.toString();
      }
    }
    catch (JMSException jmse) {
      jmse.printStackTrace();
    }
    System.out.println("There is a Message received:");
    System.out.println(msgText);
  }

#4


onMessage(Message message)方法已经有一个Message的参数 你还去receive 当然没有结果了

#5


补充 消息已经被消费掉了 Subscrib.rereceive当然收不到消息

#6


不对啊 我照着上面的方法(同步消费和异步消费)都做了,但还是接收不到消息,我把代码帖出来,大家帮忙看看:

package jmstest;

import javax.jms.*;
import javax.naming.*;
import java.util.Properties;

public class testLister implements MessageListener {

  public testLister() {
  }
  public static void main(String[] args) {
    testLister t1 = new testLister();
    try{
      t1.publish();
      t1.comsumer();
    }catch(Exception ex){
      ex.printStackTrace();
    }
  }
  public void publish() throws Exception{
    log("start publish.....");
    Context ctx = getInitialContext();
      TopicConnectionFactory tConFactory = (TopicConnectionFactory)ctx.lookup("MDBDemoCF");
      Topic newTopic = (Topic)ctx.lookup("MDBDemo Topic");
      TopicConnection tCon = tConFactory.createTopicConnection();
      TopicSession session = tCon.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
      TopicPublisher publisher = session.createPublisher(newTopic);
      TextMessage msg = session.createTextMessage();
      msg.setText("Hello");
      publisher.publish(msg);
      log("end publish.");
  }

  public void comsumer() throws Exception{
    log("start comsumer....");
      Context ctx = getInitialContext();
      TopicConnectionFactory tConFactory = (TopicConnectionFactory)ctx.lookup("MDBDemoCF");
      Topic newTopic = (Topic)ctx.lookup("MDBDemo Topic");
      TopicConnection tCon = tConFactory.createTopicConnection();
      TopicSession session = tCon.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
      TopicSubscriber subscriber = session.createSubscriber(newTopic);
      //异步
      //subscriber.setMessageListener(this);
      tCon.start();
      //同步
      TextMessage msg = (TextMessage)subscriber.receive();
      log("receiver="+msg.getText());
  }

  public void onMessage(Message message) {
    try{
    TextMessage msg = (TextMessage)message;
    System.out.println(msg.getText());
    }catch(Exception ex){
      ex.printStackTrace();
    }
  }

  private Context getInitialContext() throws NamingException {
  try {
    // Get an InitialContext
    Properties h = new Properties();
    h.put(Context.INITIAL_CONTEXT_FACTORY,
      "weblogic.jndi.WLInitialContextFactory");
    h.put(Context.PROVIDER_URL, "t3://localhost:7001");
    return new InitialContext(h);
  }catch (NamingException ex) {
    log("We were unable to get a connection to the WebLogic server at t3://localhost:7001");
    log("Please make sure that the server is running.");
    throw ex;
  }
  }

  private static void log(String s) {
    System.out.println(s);
  }

}

#7


好象消息发布者和消费者不能存在于一个类中 用嵌套类试试

#8


可以看看我的例子
http://expert.csdn.net/Expert/topic/1657/1657269.xml?temp=.6064264

#9


哦 我忘了一件事 消息发布是有一段延时 客户端不能马上收到 你做成非同步的持久订阅者
 public void comsumer() throws Exception {
    String clientID = "test";    
    log("start comsumer....");
    tCon = tConFactory.createTopicConnection();
    tCon.setClientID(clientID);
    session = tCon.createTopicSession(false,
                                      Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber subscriber = session.createDurableSubscriber(newTopic,
        clientID);
    subscriber.setMessageListener(this);
    tCon.start();
  }

在main方法里多等会就能收到

public static void main(String[] args) {
    testLister t1 = new testLister();
    try {
      t1.publish();
      t1.comsumer();
      while (true) {
        Thread.sleep(500);
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

#10


是的, teafang(学习) 说的对,有两点要注意:
1、发布后最好等待一段时间再订阅
2、最好能异步接收,并且将MessageListener写在另一个类中
好象上面都提到了,这些我也是试了两天才得出的一点教训

下面有个例子,可以运行:
http://www.net7b.com/net7b_tech/lookart.asp?id={C4902551-DAB4-4251-808D-77DA15C63289}

#11


好象消息发布者和消费者不能存在于一个类中 用嵌套类试试  这个是我错了 忘了实现messagelistener接口了 你把改了的部分覆盖了就能接收了

#12


/*
 * @(#)DurableSubscriberExample.java 1.6 00/08/18
 * 
 * Copyright (c) 2000 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */
import javax.jms.*;

/**
 * The DurableSubscriberExample class demonstrates that a durable subscription
 * is active even when the subscriber is not active.
 * 


 * The program contains a DurableSubscriber class, a MultiplePublisher class, 
 * a main method, and a method that instantiates the classes and calls their
 * methods in sequence.
 * 


 * The program begins like any publish/subscribe program: the subscriber starts,
 * the publisher publishes some messages, and the subscriber receives them.
 * 


 * At this point the subscriber closes itself.  The publisher then publishes 
 * some messages while the subscriber is not active.  The subscriber then 
 * restarts and receives the messages.
 * 


 * Specify a topic name on the command line when you run the program.
 *
 * @author Kim Haase
 * @version 1.6, 08/18/00
 */
public class DurableSubscriberExample {
    String      topicName = null;
    int         exitResult = 0;
    static int  startindex = 0;

    /**
     * The DurableSubscriber class contains a constructor, a startSubscriber 
     * method, a closeSubscriber method, and a finish method.
     * 


     * The class fetches messages asynchronously, using a message listener, 
     * TextListener.
     *
     * @author Kim Haase
     * @version 1.6, 08/18/00
     */
    public class DurableSubscriber {
        TopicConnection  topicConnection = null;
        TopicSession     topicSession = null;
        Topic            topic = null;
        TopicSubscriber  topicSubscriber = null;
        TextListener     topicListener = null;

        /**
         * The TextListener class implements the MessageListener interface by 
         * defining an onMessage method for the DurableSubscriber class.
         *
         * @author Kim Haase
         * @version 1.6, 08/18/00
         */
        private class TextListener implements MessageListener {
            final SampleUtilities.DoneLatch  monitor =
                new SampleUtilities.DoneLatch();

            /**
             * Casts the message to a TextMessage and displays its text.
             * A non-text message is interpreted as the end of the message 
             * stream, and the message listener sets its monitor state to all 
             * done processing messages.
             *
             * @param message the incoming message
             */
            public void onMessage(Message message) {
                if (message instanceof TextMessage) {
                    TextMessage  msg = (TextMessage) message;
                    
                    try {
                        System.out.println("SUBSCRIBER: Reading message: " 
                                           + msg.getText());
                    } catch (JMSException e) {
                        System.out.println("Exception in onMessage(): " 
                                           + e.toString());
                    }
                } else {
                    monitor.allDone();
                }
            }
        }

        /**
         * Constructor: looks up a connection factory and topic and creates a 
         * connection and session.
         */
        public DurableSubscriber() {
            TopicConnectionFactory  topicConnectionFactory = null;

            try {
                topicConnectionFactory = 
                    SampleUtilities.getTopicConnectionFactory();
                topicConnection = 
                    topicConnectionFactory.createTopicConnection();
                topicConnection.setClientID("EE");
                topicSession = topicConnection.createTopicSession(false, 
                    Session.AUTO_ACKNOWLEDGE);
                topic = SampleUtilities.getTopic(topicName, topicSession);
            } catch (Exception e) {
                System.out.println("Connection problem: " + e.toString());
                if (topicConnection != null) {
                    try {
                        topicConnection.close();
                    } catch (JMSException ee) {}
                }
             System.exit(1);
            } 
        }

        /**
         * Stops connection, then creates durable subscriber, registers message 
         * listener (TextListener), and starts message delivery; listener
         * displays the messages obtained.
         */
        public void startSubscriber() {
            try {
                System.out.println("Starting subscriber");
                topicConnection.stop();
                topicSubscriber = topicSession.createDurableSubscriber(topic,
                    "MakeItLast");
                topicListener = new TextListener();
                topicSubscriber.setMessageListener(topicListener);
                topicConnection.start();
            } catch (JMSException e) {
                System.out.println("Exception occurred: " + e.toString());
                exitResult = 1;
            }
        }
        
        /**
         * Blocks until publisher issues a control message indica3ting
         * end of publish stream, then closes subscriber.
         */
        public void closeSubscriber() {
            try {
                topicListener.monitor.waitTillDone();
                System.out.println("Closing subscriber");
                topicSubscriber.close();
            } catch (JMSException e) {
                System.out.println("Exception occurred: " + e.toString());
                exitResult = 1;
            }
        }
        
        /**
         * Closes the connection.
         */
        public void finish() {
            if (topicConnection != null) {
                try {
                    topicSession.unsubscribe("MakeItLast");
                    topicConnection.close();
                } catch (JMSException e) {
                    exitResult = 1;
                }
            }
        }
    }

#13


/**
     * The MultiplePublisher class publishes several messages to a topic. It
     * contains a constructor, a publishMessages method, and a finish method.
     *
     * @author Kim Haase
     * @version 1.6, 08/18/00
     */
    public class MultiplePublisher {
        TopicConnection  topicConnection = null;
        TopicSession     topicSession = null;
        Topic            topic = null;
        TopicPublisher   topicPublisher = null;

        /**
         * Constructor: looks up a connection factory and topic and creates a 
         * connection and session.  Also creates the publisher.
         */
        public MultiplePublisher() {
            TopicConnectionFactory  topicConnectionFactory = null;

            try {
                topicConnectionFactory = 
                    SampleUtilities.getTopicConnectionFactory();
                topicConnection = 
                    topicConnectionFactory.createTopicConnection();
                topicSession = topicConnection.createTopicSession(false, 
                    Session.AUTO_ACKNOWLEDGE);
                topic = SampleUtilities.getTopic(topicName, topicSession);
                topicPublisher = topicSession.createPublisher(topic);
            } catch (Exception e) {
                System.out.println("Connection problem: " + e.toString());
                if (topicConnection != null) {
                    try {
                        topicConnection.close();
                    } catch (JMSException ee) {}
                }
             System.exit(1);
            } 
        }
        
        /**
         * Creates text message.
         * Sends some messages, varying text slightly.
         * Messages must be persistent.
         */
        public void publishMessages() {
            TextMessage   message = null;
            int           i;
            final int     NUMMSGS = 3;
            final String  MSG_TEXT = new String("Here is a message");

            try {
                message = topicSession.createTextMessage();
for (i = startindex; i < startindex + NUMMSGS; i++) {
                    message.setText(MSG_TEXT + " " + (i + 1));
//topicPublisher.publish( message, DeliveryMode.PERSISTENT,8, 0);

                    //System.out.println("PUBLISHER: Publishing message: " + message.getText());
                    //topicPublisher.publish(message);

                }
TextMessage message1 = topicSession.createTextMessage();
 message1.setText("The new Pro J2EE book is now out");
 topicPublisher.publish(message1, DeliveryMode.PERSISTENT,8, 0);
 //topicPublisher.publish(message1);
                // Send a non-text control message indicating end of messages.
                topicPublisher.publish(topicSession.createMessage());
                startindex = i;
            } catch (JMSException e) {
                System.out.println("Exception occurred: " + e.toString());
                exitResult = 1;
            }
        }
        
        /**
         * Closes the connection.
         */
        public void finish() {
            if (topicConnection != null) {
                try {
                    topicConnection.close();
                } catch (JMSException e) {
                    exitResult = 1;
                }
            }
        }
    }
    
    /**
     * Instantiates the subscriber and publisher classes.
     *
     * Starts the subscriber; the publisher publishes some messages.
     *
     * Closes the subscriber; while it is closed, the publisher publishes
     * some more messages.
     *
     * Restarts the subscriber and fetches the messages.
     *
     * Finally, closes the connections.    
     */
    public void run_program_r() {
        DurableSubscriber  durableSubscriber = new DurableSubscriber();
        durableSubscriber.startSubscriber();
durableSubscriber.closeSubscriber();
        durableSubscriber.finish();
    }
public void run_program_s() {
        MultiplePublisher  multiplePublisher = new MultiplePublisher();
        multiplePublisher.publishMessages();
multiplePublisher.finish();

    }
public void run_program() {
        MultiplePublisher  multiplePublisher = new MultiplePublisher();
DurableSubscriber  durableSubscriber = new DurableSubscriber();
        
durableSubscriber.startSubscriber();
multiplePublisher.publishMessages();
durableSubscriber.closeSubscriber();

        multiplePublisher.publishMessages();
durableSubscriber.startSubscriber();
durableSubscriber.closeSubscriber();

multiplePublisher.finish();
        durableSubscriber.finish();

    }
    /**
     * Reads the topic name from the command line, then calls the
     * run_program method.
     *
     * @param args the topic used by the example
     */
    public static void main(String[] args) {
        DurableSubscriberExample  dse = new DurableSubscriberExample();
        
        dse.topicName = "jms/WroxPublications";

if(args.length != 1){
dse.run_program();
}
else if(args[0].equals("r")){
dse.run_program_r();
}else if(args[0].equals("s")){
dse.run_program_s();
}
        
     SampleUtilities.exit(dse.exitResult);
    }
}

#14


大家看看上边的例子,

#15


注意不要在jbuilder8中指定连接工厂,指定了就接收不到

推荐阅读
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 在重复造轮子的情况下用ProxyServlet反向代理来减少工作量
    像不少公司内部不同团队都会自己研发自己工具产品,当各个产品逐渐成熟,到达了一定的发展瓶颈,同时每个产品都有着自己的入口,用户 ... [详细]
  • 标题: ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 本文介绍了Python爬虫技术基础篇面向对象高级编程(中)中的多重继承概念。通过继承,子类可以扩展父类的功能。文章以动物类层次的设计为例,讨论了按照不同分类方式设计类层次的复杂性和多重继承的优势。最后给出了哺乳动物和鸟类的设计示例,以及能跑、能飞、宠物类和非宠物类的增加对类数量的影响。 ... [详细]
  • 本文介绍了在处理不规则数据时如何使用Python自动提取文本中的时间日期,包括使用dateutil.parser模块统一日期字符串格式和使用datefinder模块提取日期。同时,还介绍了一段使用正则表达式的代码,可以支持中文日期和一些特殊的时间识别,例如'2012年12月12日'、'3小时前'、'在2012/12/13哈哈'等。 ... [详细]
  • 本文介绍了解决Netty拆包粘包问题的一种方法——使用特殊结束符。在通讯过程中,客户端和服务器协商定义一个特殊的分隔符号,只要没有发送分隔符号,就代表一条数据没有结束。文章还提供了服务端的示例代码。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • 本文介绍了在使用Python中的aiohttp模块模拟服务器时出现的连接失败问题,并提供了相应的解决方法。文章中详细说明了出错的代码以及相关的软件版本和环境信息,同时也提到了相关的警告信息和函数的替代方案。通过阅读本文,读者可以了解到如何解决Python连接服务器失败的问题,并对aiohttp模块有更深入的了解。 ... [详细]
  • 网络请求模块选择——axios框架的基本使用和封装
    本文介绍了选择网络请求模块axios的原因,以及axios框架的基本使用和封装方法。包括发送并发请求的演示,全局配置的设置,创建axios实例的方法,拦截器的使用,以及如何封装和请求响应劫持等内容。 ... [详细]
  • 本文介绍了在iOS开发中使用UITextField实现字符限制的方法,包括利用代理方法和使用BNTextField-Limit库的实现策略。通过这些方法,开发者可以方便地限制UITextField的字符个数和输入规则。 ... [详细]
  • MPLS VP恩 后门链路shamlink实验及配置步骤
    本文介绍了MPLS VP恩 后门链路shamlink的实验步骤及配置过程,包括拓扑、CE1、PE1、P1、P2、PE2和CE2的配置。详细讲解了shamlink实验的目的和操作步骤,帮助读者理解和实践该技术。 ... [详细]
author-avatar
不会做饭的我
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有