创建JMSProducer时如何提高性能?

时间:2019-02-25 04:17:42

标签: java-ee jms wildfly

我已经在一个实例上运行带有嵌入式ActiveMQ Artemis的Wildfly 10实例。在第二个实例中,我通过pooled-connection-factory连接到MQ。但是,在创建JMSProducer时,性能很差。运行jProfiler显示创建生产者可能需要4到5秒钟。

@Inject
public JMSMessagePublisherServiceImpl(@JMSConnectionFactory("java:/jms/RemoteConnectionFactory") JMSContext jmsContext,) {
    this.jmsContext = jmsContext;
}

public void publishMessage(JndiEntry destination, Serializable object, String messageSelector, int priority, long timeToLive){
    if(destination == null){
        throw new IllegalArgumentException("destination cannot be empty");
    }

    // check the priority level
    Validate.inclusiveBetween(0, 9, priority, "Priority must be between 0 and 9");

    try{
        // create a topic publisher
        JMSProducer jmsProducer =   jmsContext.createProducer();
        jmsProducer.setPriority(priority);
        jmsProducer.setTimeToLive(timeToLive);

        ...
        ...

使用者JB节点的配置如下:

   <pooled-connection-factory name="remote-artemis" password="${artemis.user.password}" user="${artemis.user.name}" entries="java:/jms/RemoteConnectionFactory" connectors="remote-http-connector">
      <inbound-config jndi-params="java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory;java.naming.provider.url=${artemis.jndi.url};java.naming.security.principal=${artemis.user.name};java.naming.security.credentials=${artemis.user.password}" use-jndi="true"/>
    </pooled-connection-factory>

我该怎么做才能提高性能?每次对publishMessage()方法的调用都会创建一个新的生产者。可以将生产者合并(例如:Apache Object Pool)吗?据我了解,JMSProducer不是线程安全的。有没有更快的创建生产者的方法?

0 个答案:

没有答案