Example usage for com.rabbitmq.client MessageProperties PERSISTENT_TEXT_PLAIN

List of usage examples for com.rabbitmq.client MessageProperties PERSISTENT_TEXT_PLAIN

Introduction

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

Prototype

BasicProperties PERSISTENT_TEXT_PLAIN

To view the source code for com.rabbitmq.client MessageProperties PERSISTENT_TEXT_PLAIN.

Click Source Link

Document

Content-type "text/plain", deliveryMode 2 (persistent), priority zero

Usage

From source file:org.apache.nifi.amqp.processors.ConsumeAMQPTest.java

License:Apache License

@Test
public void validateSuccessfullConsumeAndTransferToSuccess() throws Exception {
    Map<String, List<String>> routingMap = new HashMap<>();
    routingMap.put("key1", Arrays.asList("queue1", "queue2"));
    Map<String, String> exchangeToRoutingKeymap = new HashMap<>();
    exchangeToRoutingKeymap.put("myExchange", "key1");

    Connection connection = new TestConnection(exchangeToRoutingKeymap, routingMap);

    try (AMQPPublisher sender = new AMQPPublisher(connection, mock(ComponentLog.class))) {
        sender.publish("hello".getBytes(), MessageProperties.PERSISTENT_TEXT_PLAIN, "key1", "myExchange");

        ConsumeAMQP pubProc = new LocalConsumeAMQP(connection);
        TestRunner runner = TestRunners.newTestRunner(pubProc);
        runner.setProperty(ConsumeAMQP.HOST, "injvm");
        runner.setProperty(ConsumeAMQP.QUEUE, "queue1");

        runner.run();/*from w w  w  .  j  ava 2  s. co m*/
        Thread.sleep(200);
        final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishAMQP.REL_SUCCESS).get(0);
        assertNotNull(successFF);
    }

}

From source file:org.atmosphere.plugin.rabbitmq.RabbitMQBroadcaster.java

License:Apache License

public void outgoingBroadcast(Object message) {
    try {/*from  w w w . j  a  v a  2  s .co  m*/
        String id = getID();
        if (message instanceof String) {
            logger.trace("Outgoing broadcast : {}", message);

            channel.basicPublish(exchangeName, id, MessageProperties.PERSISTENT_TEXT_PLAIN,
                    message.toString().getBytes());
        } else {
            throw new IOException("Message is not a string, so could not be handled !");
        }

    } catch (IOException e) {
        logger.warn("Failed to send message over RabbitMQ", e);
    }
}

From source file:org.atmosphere.samples.pubsub.rabbitmq.RabbitMQBroadcaster.java

License:Apache License

public void outgoingBroadcast(Object message) {
    try {//www  .  j ava  2 s.c om
        String id = getID();
        logger.trace("Outgoing broadcast : {}", message);

        channel.basicPublish(exchangeName, id, MessageProperties.PERSISTENT_TEXT_PLAIN,
                message.toString().getBytes());

    } catch (IOException e) {
        logger.warn("Failed to send message over RabbitMQ", e);
    }
}

From source file:org.atmosphere.samples.websockethub.RabbitMQRouter.java

License:Apache License

public RabbitMQRouter deliver(String amqRoutingKey, String broadcasterRoutingKey, String message) {
    try {/*w  ww  .  j  a  va2s. co  m*/
        channel.basicPublish(exchangeName, amqRoutingKey, MessageProperties.PERSISTENT_TEXT_PLAIN,
                oMapper.writeValueAsBytes(new Message(broadcasterRoutingKey, message)));
    } catch (IOException e) {
        logger.warn("Failed to send message over RabbitMQ", e);
    }
    return this;
}

From source file:org.belio.mq.RabbitConsumer.java

private void publish(OutboxList outboxList) throws IOException {
    openPublisher();/*from ww  w .j  av  a2  s.  co m*/
    final String message = xStream.toXML(outboxList);
    publishingChannel.basicPublish(queueType.name().concat(EXCHANGE_SUFFIX),
            queueType.name().concat(QUEUE_SUFFIX), MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
    Launcher.LOG.info("Republished " + outboxList);
    closePublisher();
}

From source file:org.belio.mq.RabbitPublisher.java

@Override
public void publish() {
    try {//  w  w w  .  j  a va  2s .c  om
        open();
    } catch (IOException ex) {
        Logger.getLogger(RabbitPublisher.class.getName()).log(Level.SEVERE, null, ex);
    }
    //        synchronized (this) {
    OutboxList outboxList = new OutboxList(queueType);
    outboxList.setOutboxes((ArrayList<Outbox>) messageQueue);
    Long startTime = System.currentTimeMillis();
    int MQTHREADS = 3;
    ExecutorService executor = Executors.newFixedThreadPool(MQTHREADS);

    try {
        channel.txSelect();
        dbReader.insertSublistBatch(messageQueue);
        // check that insert is complete
        int alertsSaved = dbReader.saveAlertsToOutboxCount(alert);
        if (alertsSaved == messageQueue.size()) {
            Launcher.LOG.info("publishing " + alert + " to " + alert.getType().name());
            // create a map that will hold the outbox lists of different networks
            Map<String, OutboxList> map = new HashMap<>();
            // loop through the messages to add them onto outbox lists in batches of 10
            for (Outbox outbox : outboxList.getOutboxes()) {
                // check if the map contains an outbox list of the network
                if (map.containsKey(outbox.getNetwork())) {
                    // check if the max of 10 has been reached in the size of the outboxlist
                    if (map.get(outbox.getNetwork()).getOutboxes().size() < Integer
                            .parseInt(threadproperties.getProperty("batch_size"))) {
                        // add the outbox to the outboxlist if the size is less than 10
                        map.get(outbox.getNetwork()).add(outbox);
                    } else {
                        // publish the outboxlist to MQ and reset the outboxlist 
                        OutboxList ol = map.get(outbox.getNetwork());
                        final String message = xStream.toXML(ol);

                        Runnable worker = new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    channel.basicPublish(alert.getType().name().concat(EXCHANGE_SUFFIX),
                                            alert.getType().name().concat(QUEUE_SUFFIX),
                                            MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
                                } catch (IOException ex) {
                                    Logger.getLogger(RabbitPublisher.class.getName()).log(Level.SEVERE, null,
                                            ex);
                                }
                            }
                        };
                        executor.execute(worker);
                        // clear the outboxlist of the network
                        map.get(outbox.getNetwork()).getOutboxes().clear();
                    }
                } else {
                    // create the outbox list for the network
                    map.put(outbox.getNetwork(), new OutboxList(queueType));
                    // add an outbox to the outboxlist
                    map.get(outbox.getNetwork()).add(outbox);
                }

            }
            // get the iterator of the entries in the map for publishing
            for (Map.Entry<String, OutboxList> entry : map.entrySet()) {
                // publish the outboxlist to MQ and reset the outboxlist 
                OutboxList ol = entry.getValue();
                final String message = xStream.toXML(ol);

                Runnable worker = new Runnable() {

                    @Override
                    public void run() {
                        try {
                            channel.basicPublish(alert.getType().name().concat(EXCHANGE_SUFFIX),
                                    alert.getType().name().concat(QUEUE_SUFFIX),
                                    MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
                        } catch (IOException ex) {
                            Logger.getLogger(RabbitPublisher.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                };
                executor.execute(worker);
                // clear the outboxlist of the network
                entry.getValue().getOutboxes().clear();
            }

            channel.txCommit();
            dbReader.updateAlertStatus(alert, "SENT", messageQueue.size(),
                    new Timestamp(Calendar.getInstance().getTimeInMillis()));
            dbReader.deleteCSVFile(alert);
        } else {
            channel.txRollback();
            Launcher.LOG.info("unable to publish " + alert + " to " + alert.getType().name() + " " + alertsSaved
                    + " - " + messageQueue.size());
            dbReader.updateAlertStatus(alert, "UNSENT", null, null);
            //TO:DO
            //delete from outboxes where alert
            dbReader.deleteCSVFile(alert);
        }
    } catch (IOException exception) {
        Launcher.LOG.error("Error publishing", exception);
        //TODO log exception
        dbReader.updateAlertStatus(alert, "UNSENT", null, null);
        dbReader.deleteCSVFile(alert);
        //TO:DO
        //delete from outboxes where alert
        // reset message to unsent
        //failedMessageQueue.add(queuable);
        try {
            channel.txRollback();
        } catch (IOException ioe) {
            //TODO log message
        }
    }
    Long endTime = System.currentTimeMillis();
    Long timeTaken = endTime - startTime;
    Launcher.LOG.info("Took " + timeTaken + " to publish");
    try {
        //        System.exit(0);
        close();
    } catch (IOException ex) {
        Logger.getLogger(RabbitPublisher.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.openmrs.module.amqpmodule.utils.impl.PublisherServiceImpl.java

License:Open Source License

@Override
public boolean PublisherCreateConnection() throws java.io.IOException {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("192.168.43.123");
    factory.setPort(5672);// w w  w . jav  a2  s.co  m
    factory.setUsername("chs");
    factory.setPassword("chs123");
    Connection connection = null;
    try {
        connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, "direct", true);

        channel.basicPublish(EXCHANGE_NAME, topic, MessageProperties.PERSISTENT_TEXT_PLAIN, msg.getBytes());
        System.out.println(" [x] Sent '" + msg + "'");

        channel.close();

    } catch (TimeoutException e) {
        System.out.println("Connection Timed out");
        e.printStackTrace();
    }

    connection.close();

    return true;
}

From source file:org.sdw.scheduler.PeriodicUpdater.java

License:Apache License

/**
 * Pushes messages to the shared queue on execution of triggers
 * @param JobExecutionContext Job execution context
 * @throws JobExecutionException //from  w w w.j  a  v a 2s .co m
 */
@Override
public void execute(JobExecutionContext jobExecutionContext) {
    try {
        Connection connection = PeriodicScheduler.factory.newConnection();
        Channel channel = connection.createChannel();
        String queueName = "work-queue-1";
        Map<String, Object> params = new HashMap<>();
        params.put("x-ha-policy", "all");
        channel.queueDeclare(queueName, true, false, false, params);
        String mesg = "Sent at: " + System.currentTimeMillis();
        byte[] body = mesg.getBytes("UTF-8");
        channel.basicPublish("", queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, body);
        LOG.info("Message sent: " + mesg);
        connection.close();
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
    }
}

From source file:org.thingsboard.rule.engine.rabbitmq.TbRabbitMqNode.java

License:Apache License

private static AMQP.BasicProperties convert(String name) throws TbNodeException {
    switch (name) {
    case "BASIC":
        return MessageProperties.BASIC;
    case "TEXT_PLAIN":
        return MessageProperties.TEXT_PLAIN;
    case "MINIMAL_BASIC":
        return MessageProperties.MINIMAL_BASIC;
    case "MINIMAL_PERSISTENT_BASIC":
        return MessageProperties.MINIMAL_PERSISTENT_BASIC;
    case "PERSISTENT_BASIC":
        return MessageProperties.PERSISTENT_BASIC;
    case "PERSISTENT_TEXT_PLAIN":
        return MessageProperties.PERSISTENT_TEXT_PLAIN;
    default:/*from   ww w .  jav a 2 s  .c o  m*/
        throw new TbNodeException("Message Properties: '" + name + "' is undefined!");
    }
}

From source file:org.thingsboard.server.extensions.rabbitmq.plugin.RabbitMqMsgHandler.java

License:Apache License

private static AMQP.BasicProperties convert(String name) throws RuleException {
    switch (name) {
    case "BASIC":
        return MessageProperties.BASIC;
    case "TEXT_PLAIN":
        return MessageProperties.TEXT_PLAIN;
    case "MINIMAL_BASIC":
        return MessageProperties.MINIMAL_BASIC;
    case "MINIMAL_PERSISTENT_BASIC":
        return MessageProperties.MINIMAL_PERSISTENT_BASIC;
    case "PERSISTENT_BASIC":
        return MessageProperties.PERSISTENT_BASIC;
    case "PERSISTENT_TEXT_PLAIN":
        return MessageProperties.PERSISTENT_TEXT_PLAIN;
    default://from  w  ww .  j  a  v a  2s.c  o  m
        throw new RuleException("Message Properties: '" + name + "' is undefined!");
    }
}