@Override
 public boolean offer(T event) throws FalconException {
   Session session;
   try {
     session = getSession();
     TextMessage msg = session.createTextMessage(event.toString());
     msg.setLongProperty(
         ScheduledMessage.AMQ_SCHEDULED_DELAY, event.getDelay(TimeUnit.MILLISECONDS));
     msg.setStringProperty("TYPE", event.getType().name());
     producer.send(msg);
     LOG.debug(
         "Enqueued Message: {} with delay {} milli sec",
         event.toString(),
         event.getDelay(TimeUnit.MILLISECONDS));
     return true;
   } catch (Exception e) {
     LOG.error("Unable to offer event: {} to ActiveMQ", event, e);
     throw new FalconException("Unable to offer event:" + event + " to ActiveMQ", e);
   }
 }
 @Override
 public T take() throws FalconException {
   try {
     TextMessage textMessage = (TextMessage) consumer.receive();
     T event =
         new RerunEventFactory<T>()
             .getRerunEvent(textMessage.getStringProperty("TYPE"), textMessage.getText());
     LOG.debug("Dequeued Message: {}", event.toString());
     return event;
   } catch (Exception e) {
     LOG.error("Error getting the message from ActiveMQ", e);
     throw new FalconException("Error getting the message from ActiveMQ: ", e);
   }
 }
  public void invoke(T message) throws EndpointException {
    MessageProducer messageProducer = null;
    Message jmsMessage = null;

    try {
      messageProducer = session.createProducer(destination);

      if (message instanceof FlowEvent) {
        jmsMessage = this.convertToMessage(((FlowEvent) message).getPayload());

        // carry the event identifier if available
        this.managedEventIdentifierService.setEventIdentifier(
            ((FlowEvent<String, ?>) message).getIdentifier(), jmsMessage);
      } else {
        jmsMessage = this.convertToMessage(message);
      }

      // pass original message to getMessageProperties to allow overridding classes to implement
      // custom processing
      // and set whatever comes back as properties on the message
      setMessageProperties(jmsMessage, getMessageProperties(message));

      // allow programmatic overrride of properties
      if (customMessagePropertyProvider != null) {
        setMessageProperties(jmsMessage, customMessagePropertyProvider.getProperties(message));
      }

      // publish message
      messageProducer.send(jmsMessage);
      if (logger.isDebugEnabled()) {
        logger.debug("Published [" + message.toString() + "]");
      }

    } catch (JMSException e) {
      throw new EndpointException(e);
    } finally {
      if (messageProducer != null) {
        try {
          messageProducer.close();
          messageProducer = null;
        } catch (JMSException e) {
          logger.error("Failed to close session", e);
        }
      }
    }
  }