Example usage for com.rabbitmq.client ConnectionFactory ConnectionFactory

List of usage examples for com.rabbitmq.client ConnectionFactory ConnectionFactory

Introduction

In this page you can find the example usage for com.rabbitmq.client ConnectionFactory ConnectionFactory.

Prototype

ConnectionFactory

Source Link

Usage

From source file:com.preferya.facadesmsgatewayrouter.utils.RabbitMQUtils.java

public RabbitMQUtils(String countryCode) throws IOException {
    this.task_queue_name = countryCode;

    this.factory = new ConnectionFactory();
    this.factory.setHost("localhost");
    this.connection = this.factory.newConnection();
    this.channel = this.connection.createChannel();

    //this.channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
    this.channel.queueDeclare(task_queue_name, true, false, false, null);

    this.channel.basicQos(1);

    this.consumer = new QueueingConsumer(channel);
    this.channel.basicConsume(task_queue_name, false, consumer);

}

From source file:com.preferya.facadesmsgatewayservlet.utils.RabbitMQUtils.java

public RabbitMQUtils() throws IOException {
    this.factory = new ConnectionFactory();
    this.factory.setHost("localhost");
    this.connection = factory.newConnection();
    this.channel = connection.createChannel();

    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
}

From source file:com.preferya.queuesmsgateway.utils.NewTasker.java

public NewTasker(String iso_country) throws IOException {
    this.factory = new ConnectionFactory();
    this.factory.setHost("localhost");
    this.connection = this.factory.newConnection();
    this.channel = this.connection.createChannel();

    this.task_queue_name = iso_country;

    this.channel.queueDeclare(this.task_queue_name, true, false, false, null);
}

From source file:com.preferya.queuesmsgateway.utils.Worker.java

public Worker() throws IOException {
    this.factory = new ConnectionFactory();
    this.factory.setHost("localhost");
    this.connection = this.factory.newConnection();
    this.channel = this.connection.createChannel();

    this.channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

    this.channel.basicQos(1);

    this.consumer = new QueueingConsumer(this.channel);
    this.channel.basicConsume(TASK_QUEUE_NAME, false, this.consumer);
}

From source file:com.project.finalproject.finalBean.java

/**
 * Creates a new instance of finalBean// w  w  w .  j  a  v  a 2 s  .  co  m
 */
public finalBean(LineChartModel chart) throws IOException {
    factory = new ConnectionFactory();
    factory.setHost("localhost");
    connection = factory.newConnection();
    channel = connection.createChannel();
    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
    this.chart = chart;
    cs.setLabel("Heart Rate");
    initConsumer();
}

From source file:com.project.finalproject.Recv.java

public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    Consumer consumer = new DefaultConsumer(channel) {
        @Override//from w  w  w  .j a v  a2  s  .  co  m
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                byte[] body) throws IOException {
            String message = new String(body, "UTF-8");

            System.out.println(" [x] Received '" + message + "'");
        }
    };
    channel.basicConsume(QUEUE_NAME, true, consumer);
}

From source file:com.project.finalproject.Send.java

public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(QUEUE_NAME, false, false, false, null);

    try {//from  www.  j a  v a  2 s  .c o m
        InputStream is = new FileInputStream("hr.json");
        String jsontxt = IOUtils.toString(is);
        JSONObject jsonObject = new JSONObject(jsontxt);
        JSONArray stream = jsonObject.getJSONArray("stream");
        for (int i = 0; i < stream.length(); i++) {
            String message = stream.getJSONObject(i).getString("value");
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
            System.out.println(" [x] Sent '" + message + "'");
            TimeUnit.SECONDS.sleep(1);
        }
    } catch (FileNotFoundException fe) {
        fe.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    channel.close();
    connection.close();
}

From source file:com.qt.core.util.MqConnectionUtil.java

License:Open Source License

private Connection createPooledConnection(MqConn conn) throws IOException {
    ConnectionFactory connectionFactory = new ConnectionFactory(); // 
    connectionFactory.setHost(conn.getHost());
    connectionFactory.setPort(conn.getPort());
    connectionFactory.setUsername(conn.getAccount());
    connectionFactory.setPassword(conn.getPassword());
    Connection connection = connectionFactory.newConnection();
    return connection;
}

From source file:com.saasovation.common.port.adapter.messaging.rabbitmq.BrokerChannel.java

License:Apache License

/**
 * Answers a new ConnectionFactory configured with aConnectionSettings.
 * @param aConnectionSettings the ConnectionFactory
 * @return ConnectionFactory/* w w w . ja v a  2s  .  co m*/
 */
protected ConnectionFactory configureConnectionFactoryUsing(ConnectionSettings aConnectionSettings) {

    ConnectionFactory factory = new ConnectionFactory();

    factory.setHost(aConnectionSettings.hostName());

    if (aConnectionSettings.hasPort()) {
        factory.setPort(aConnectionSettings.port());
    }

    factory.setVirtualHost(aConnectionSettings.virtualHost());

    if (aConnectionSettings.hasUserCredentials()) {
        factory.setUsername(aConnectionSettings.username());
        factory.setPassword(aConnectionSettings.password());
    }

    return factory;
}

From source file:com.service.OperationFacadeREST.java

@POST
@Override// w  ww  .j ava2  s  .  c o  m
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void create(Operation entity) {
    if (!entity.getState().equals("waiting")) {
        super.create(entity);
        return;
    }
    if (entity.getOperationType())//venda
    {
        ArrayList<ClientStock> l = new ArrayList<>(getEntityManager()
                .find(Client.class, entity.getFkOwnerId().getClientId()).getClientStockCollection());
        Boolean fail = false;
        for (int i = 0; i < l.size(); i++) {
            if (l.get(i).getStock().equals(entity.getFkStockId())) {
                if (l.get(i).getQuantity() < entity.getQuantity())
                    return;
                l.get(i).setQuantity(l.get(i).getQuantity() - entity.getQuantity());
                getEntityManager().persist(l.get(i));
                entity.getFkOwnerId().setClientStockCollection(l);

                entity.setCreationDate(Date.from(Instant.now()));
                super.create(entity);
            }
        }
        if (fail)
            return;
    } else {
        entity.setCreationDate(Date.from(Instant.now()));
        if (entity.getFkStockId().getQuantity() > entity.getQuantity()) {

            System.out.println("yes");
            super.create(entity);
        } else {
            return;
        }
    }

    try {

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare("hello", false, false, false, null);
        System.out.println(super.findAll().get(super.findAll().size() - 1).getOperationId() + ","
                + entity.getFkOwnerId().getName() + "," + entity.getFkStockId().getName() + ","
                + entity.getQuantity());

        String message = super.findAll().get(super.findAll().size() - 1).getOperationId() + ","
                + entity.getFkOwnerId().getName() + "," + entity.getFkStockId().getName() + ","
                + entity.getQuantity();
        channel.basicPublish("", "hello", null, message.getBytes());
        System.out.println(" [x] Sent '" + message + "'");
        channel.close();
        connection.close();
    } catch (IOException ex) {
        Logger.getLogger(ClientFacadeREST.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TimeoutException ex) {
        Logger.getLogger(ClientFacadeREST.class.getName()).log(Level.SEVERE, null, ex);
    }
}