发送jms消息会导致警告

时间:2016-07-22 12:39:28

标签: wildfly-10 jms-topic

通过JMS主题发送消息时,我经常收到以下警告:

2016-07-22 14:32:02,418 WARN  [org.apache.activemq.artemis.jms.client] (Finalizer) AMQ122000: I''m closing a JMS connection you left open. Please make sure you close all JMS connections explicitly before letting them go out of scope! see stacktrace to find out where it was created: java.lang.Exception
at org.apache.activemq.artemis.jms.client.ActiveMQConnection.<init>(ActiveMQConnection.java:155)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:750)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createContext(ActiveMQConnectionFactory.java:255)
at org.wildfly.extension.messaging.activemq.deployment.JMSContextProducer$JMSContextWrapper.create(JMSContextProducer.java:195)
at org.wildfly.extension.messaging.activemq.deployment.JMSContextProducer$JMSContextWrapper.getDelegate(JMSContextProducer.java:235)
at org.wildfly.extension.messaging.activemq.deployment.JMSContextProducer$JMSContextWrapper.createProducer(JMSContextProducer.java:270)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:395)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:202)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)

我的代码:

@Inject
@JMSConnectionFactory("java:/ConnectionFactory")
private JMSContext context;

@Resource(lookup = "java:/jms/topic/MyTopic", type = Long.class)
private Topic topic;

public void sendMessage(Event event) {
    try {
        context.createProducer().send(topic, 1L);
    } catch (Exception e) {;
        log.error("Error while sending message to the JMS topic. Will retry later.", e);
    }
}

有什么想法吗?我还没在谷歌上找到任何东西。

根据JMSContext javadoc,连接应该在应用程序服务器管理时自动关闭。

1 个答案:

答案 0 :(得分:0)

我认为这条消息清楚地解释了这个问题。可能你只需要在你创建的生产者上调用close()或某种类型。

编辑:

实际上,不是需要关闭的产品,而是上下文。

来自doc(https://docs.oracle.com/javaee/7/api/javax/jms/JMSContext.html):

  

所有这些JMSContext对象都是应用程序管理的,必须是   通过调用他们的关闭方法不再需要时关闭。

关于制作人,它说(https://docs.oracle.com/javaee/7/api/javax/jms/JMSProducer.html):

  

JMSProducer的实例旨在成为轻量级对象   可以自由创建,不消耗大量资源。   因此,该接口不提供紧密的方法。