/*
 * The MIT License
 *
 * Copyright (c) 2016 Marcelo "Ataxexe" Guimarães <ataxexe@devnull.tools>
 *
 * Permission  is hereby granted, free of charge, to any person obtaining
 * a  copy  of  this  software  and  associated  documentation files (the
 * "Software"),  to  deal  in the Software without restriction, including
 * without  limitation  the  rights to use, copy, modify, merge, publish,
 * distribute,  sublicense,  and/or  sell  copies of the Software, and to
 * permit  persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * The  above  copyright  notice  and  this  permission  notice  shall be
 * included  in  all  copies  or  substantial  portions  of the Software.
 *
 * THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY OF ANY KIND,
 * EXPRESS  OR  IMPLIED,  INCLUDING  BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN  NO  EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM,  DAMAGES  OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT  OR  OTHERWISE,  ARISING  FROM,  OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE   OR   THE   USE   OR   OTHER   DEALINGS  IN  THE  SOFTWARE.
 */

package tools.devnull.boteco.client.jms.impl;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.devnull.boteco.TargetSelector;
import tools.devnull.boteco.client.jms.JmsClient;
import tools.devnull.boteco.client.jms.JmsDestination;

import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import java.io.Serializable;

public class AMQClient implements JmsClient {

  private static Logger logger = LoggerFactory.getLogger(AMQClient.class);

  private final QueueConnectionFactory connectionFactory;

  public AMQClient(String user, String password, String connectionUrl) {
    this.connectionFactory = new ActiveMQConnectionFactory(user, password, connectionUrl);
  }

  public AMQClient(String connectionUrl) {
    this.connectionFactory = new ActiveMQConnectionFactory(connectionUrl);
  }

  @Override
  public TargetSelector<JmsDestination> send(Serializable object) {
    return target -> {
      try {
        Connection connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = target.createDestination(session);

        MessageProducer producer = session.createProducer(destination);
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);

        ObjectMessage message = session.createObjectMessage(object);
        producer.send(message);

        session.close();
        connection.close();
      } catch (JMSException e) {
        logger.error("Error while sending object to AMQ destination", e);
      }
    };
  }
}

@@ -1833,16 +1833,69 @@
 zable;%0A%0A
+/**%0A * The AMQ implementation for the JMS Client%0A */%0A
 public c
@@ -2068,16 +2068,229 @@
 ctory;%0A%0A
+  /**%0A   * Creates a new client based on the given parameters%0A   *%0A   * @param user          the broker user%0A   * @param password      the broker password%0A   * @param connectionUrl the broker url to connect%0A   */%0A
   public
@@ -2450,16 +2450,136 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Creates a new client based on the broker url.%0A   *%0A   * @param connectionUrl the broker url to connect%0A   */%0A
   public

add docs