In my java swing application i've implemented a jms client which communicates with a jms server. This works fine.
Currently when my application starts i create a connection and a session:
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Next when i need to send a message to a topic i create a topic (to send the message to), a temp queue (to receive replies), a producer (to send the message) and a consumer (to actual read the replies):
Destination destination = session.createTopic ...
MessageProducer producer = session.createProducer ...
Destination tempDest = session.createTemporaryQueue();
MessageConsumer responseConsumer = session.createConsumer(tempDest);
producer.send(msg);
I was wondering what is the best practice in this case?
Can i simply create everything when i need to send a message or may it be better to save the Destination, MessageProducer , MessageConsumer somewhere and re-use it. Is there something special i need to pay attention to when i decide to re-use the objects?