Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java TIBCO JMS队列消息接收器卡住_Java_Web Services_Jms_Message Queue_Tibco - Fatal编程技术网

Java TIBCO JMS队列消息接收器卡住

Java TIBCO JMS队列消息接收器卡住,java,web-services,jms,message-queue,tibco,Java,Web Services,Jms,Message Queue,Tibco,嗨,我创建了下面的类来读取jibco jms队列中的消息。在另一个类中,我创建了这个类的一个实例,并尝试将getMessage()转换为一个stirng。我在队列中放置了一条消息,当我调用getMessage()方法时,我的应用程序卡住了。。。有什么想法吗?或者是我可以在课下增加的进步 public class EMSReceiver { private QueueConnection connection; private QueueReceiver queueReceive

嗨,我创建了下面的类来读取jibco jms队列中的消息。在另一个类中,我创建了这个类的一个实例,并尝试将getMessage()转换为一个stirng。我在队列中放置了一条消息,当我调用getMessage()方法时,我的应用程序卡住了。。。有什么想法吗?或者是我可以在课下增加的进步

public class EMSReceiver {

    private QueueConnection connection;
    private QueueReceiver queueReceiver;
    private Queue queue;

    private TextMessage message;

    public EMSReceiver(String initialContextFactory, String userName, String password, String serverUrl, String confact, String q){
        try {

            Properties env = new Properties();
            env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
            env.put(Context.SECURITY_PRINCIPAL, userName);
            env.put(Context.SECURITY_CREDENTIALS, password);
            env.put(Context.PROVIDER_URL, serverUrl);

            InitialContext jndi = new InitialContext(env);

            QueueConnectionFactory connectionFactory = (QueueConnectionFactory) jndi.lookup(confact);
            QueueConnection connection = connectionFactory.createQueueConnection(userName, password);
            QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            this.queue = (Queue) jndi.lookup(q);
            this.queueReceiver = session.createReceiver(queue);

            connection.start();

        }
        catch (JMSException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }

    public String getMessage() throws JMSException{

        try {
            this.message = (TextMessage) queueReceiver.receive();
        } catch (JMSException e) {
            System.out.println("Could not retrieve the message.");
            e.printStackTrace();
        }
        return message.getText();

    }

queueReceiver.receive()
方法将等待,直到它收到队列中的消息。如果不想等待,请使用
receiveNoWait()
receive(长超时)
。相关文档可在此处找到:。

能否共享将消息放入队列的代码?好的。无论我如何放置消息。。。上面的代码应该打印字符串还是空?它不应该挂起…它将等待队列中收到消息。如果不想等待,请使用receiveNoWait()或receive(长超时)。相关文档可在此处找到:。谢谢@Priyesh。“我想这正是我想要的。”普里耶什补充说,作为答案,我会接受的。