【问题标题】:Sending message to JMS (Weblogic)向 JMS (Weblogic) 发送消息
【发布时间】:2017-12-27 05:06:28
【问题描述】:

当我运行以下代码时,似乎消息已发送到队列,但我在队列中看不到任何东西。没有错误,执行我的代码时出现异常。

我使用 Weblogic 服务器。

这是我的代码:

private InitialContext getInitialContext() throws NamingException {
    Hashtable env = new Hashtable();
    env.put(InitialContext.INITIAL_CONTEXT_FACTORY, contextFactory);
    env.put(InitialContext.PROVIDER_URL, providerUrl);
    env.put(Context.SECURITY_PRINCIPAL, username);
    env.put(Context.SECURITY_CREDENTIALS, password);
    return new InitialContext(env);
}

public ConnectionFactory getConnectionFactory(InitialContext context) throws NamingException {
    return (ConnectionFactory) context.lookup(ConnectionParameter.JMS_CONNECTION_FACTORY_JNDI);
}

public void send() throws NamingException, JMSException {
    InitialContext context = getInitialContext();
    Destination destination = (Destination) context.lookup("jms/dpdr/mhcinterface/arnoldQueue");

    try (Connection connection = getConnectionFactory(context).createConnection();){
        Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        MessageProducer sender = session.createProducer(destination);
        Message message = session.createTextMessage("work order complete!");
        sender.send(message);
        session.commit();
        session.close();
    }
    context.close();

    System.out.println("-- end --");
}

知道这里有什么问题吗?

【问题讨论】:

    标签: queue jms weblogic message-queue weblogic12c


    【解决方案1】:

    您好像忘记在发送消息之前调用 connection.start() 了。你可以这样做:

    MessageProducer sender = session.createProducer(destination);
    connection.start();
    Message message = session.createTextMessage("work order complete!");
    

    【讨论】:

      猜你喜欢
      • 2016-03-05
      • 1970-01-01
      • 2013-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 1970-01-01
      • 2015-08-25
      相关资源
      最近更新 更多