title: ActiveMQ How to handle closed session
body: <p>I am using ActiveMQ to enqueue email messages, the consumer reads the queue and sends out emails.</p>
  
  <p>At startup, I register a producer and cache it forever.</p>
  
  <pre><code>PooledConnectionFactory factory = new PooledConnectionFactory(new ActiveMQConnectionFactory(jmsBrokerUserName, jmsBrokerPassword, activeMQBrokerURL));
  Connection connection = factory.createConnection();
  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  Destination destination = session.createQueue(queueName);
  MessageProducer producer = session.createProducer(destination);
  </code></pre>
  
  <p>From time to time, the producer fails to enqueue the message as the connection gets closed.</p>
  
  <pre><code>Caused by: javax.jms.IllegalStateException: The Session is closed
      at org.apache.activemq.ActiveMQSession.checkClosed(ActiveMQSession.java:767) ~[activemq-client-5.10.0.jar:5.10.0]
      at org.apache.activemq.ActiveMQSession.configureMessage(ActiveMQSession.java:755) ~[activemq-client-5.10.0.jar:5.10.0]
      at org.apache.activemq.ActiveMQSession.createTextMessage(ActiveMQSession.java:438) ~[activemq-client-5.10.0.jar:5.10.0]
      at org.apache.activemq.jms.pool.PooledSession.createTextMessage(PooledSession.java:242) ~[activemq-jms-pool-5.10.0.jar:5.10.0]
  </code></pre>
  
  <p>Can somebody please let me know what is the best way to handle closed sessions? Should I re-register my producer? Or is there a way to reopen session?</p>