早上好,
我是JMS技术的新用户,尤其是ActiveMQ解决方案。我的应用程序性能有些问题。具体来说,我正在开发一个24x7应用程序。我们正在为所有消费者使用MessageListener。我的规格:
这是我的申请:
**Producer code - main class -**
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url+"?jms.prefetchPolicy.all=1");
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(subject);
MessageProducer producer = session.createProducer(destination);
while (true)
{
Event evento = new Event("Event1");
ObjectMessage msj = session.createObjectMessage(event);
msj5.setJMSType(msj5.getClass().getSimpleName());
msj5.setJMSReplyTo(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.send(msj5, DeliveryMode.NON_PERSISTENT, 5, 0);
Thread.sleep(1000);
}
**Consumer code -main class-**
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url+"?jms.prefetchPolicy.all=1");
Connection connection = connectionFactory.createConnection();
session = connection.createSession(true, 0);
Destination destination = session.createQueue(subject);
MessageConsumer consumer = session.createConsumer(destination);
//This is my listener
Escuchador escuchador = new Escuchador();
consumer.setMessageListener(escuchador);
connection.start();
**Listener code**
public void onMessage(Message message)
{
if (message instanceof ObjectMessage)
{
try
{
ObjectMessage msj = (ObjectMessage) message;
Object obj = msj.getObject();
if (obj instanceof Event)
{
Event event = (Event) obj;
System.out.println("Event: " + event.toString());
}
}
catch (JMSException e)
{
System.out.println("Error at ObjectMessage");
}
}
}
消费者和生产者都是从一个主类中执行的,它创建了两个实例(每个实例一个)。然后,我制作了一个可运行的jar文件,然后从JProfiler工具运行它。在结果中出现“ActiveMQObjectMessage”和“MessageId”引用(在Recorded objects视图中),以及“getObject”和“createObjectMessage”(在分配热点中)。当我走进他们每个人(看到他的命令和夸张的参考)我总是实现“activeMQSession”对象。
关键是我无法关闭我的连接或会话对象,因为我不想停止我的24x7服务。我的问题是:它可能吗?或者我需要关闭连接以提高性能?
提前致谢
此致