Example usage for com.rabbitmq.client MessageProperties TEXT_PLAIN

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

Introduction

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

Prototype

BasicProperties TEXT_PLAIN

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

Click Source Link

Document

Content-type "text/plain", deliveryMode 1 (nonpersistent), priority zero

Usage

From source file:com.hpe.caf.worker.testing.QueueManager.java

License:Apache License

public void publish(TaskMessage message) throws CodecException, IOException {
    byte[] data = workerServices.getCodec().serialise(message);
    pubChan.basicPublish("", queueServices.getWorkerInputQueue(), MessageProperties.TEXT_PLAIN, data);
    if (debugEnabled) {
        debugPubChan.basicPublish("", debugInputQueueName, MessageProperties.TEXT_PLAIN, data);
    }/*from ww  w  . ja va 2s. co m*/
}

From source file:com.hpe.caf.worker.testing.QueueManager.java

License:Apache License

public void publishDebugOutput(TaskMessage message) throws CodecException, IOException {
    byte[] data = workerServices.getCodec().serialise(message);
    debugConChan.basicPublish("", debugOutputQueueName, MessageProperties.TEXT_PLAIN, data);
}

From source file:com.omniti.reconnoiter.broker.RabbitListener.java

License:Open Source License

public void processEvent(EventBean event) {
    JSONEventRenderer jsonRenderer = epService.getEPRuntime().getEventRenderer()
            .getJSONRenderer(sq.getStatement().getEventType());

    String output = jsonRenderer.render(sq.getName(), event);
    try {//  w  w w  .ja va 2s . c om
        byte[] messageBodyBytes = output.getBytes();
        broker.getChannel().basicPublish(exchangeName, routingKey, MessageProperties.TEXT_PLAIN,
                messageBodyBytes);
    } catch (Exception e) {
        System.err.println(e);
        try {
            broker.disconnect();
            broker.connect();
        } catch (Exception be) {
            System.err.println(be);
        }
    }
}

From source file:net.lshift.camdisplay.Main.java

License:Open Source License

public void setupWindowDressing(final String exchangeName, final String nickname, JFrame frame,
        JPanel componentPanel) {/*  ww  w. j a va  2 s.  c o m*/
    componentPanel.setBackground(Color.WHITE);
    componentPanel.setBorder(new TitledBorder("Channel '" + exchangeName + "'"));

    ImageIcon icon = new ImageIcon(Main.class.getResource("/resources/RabbitMQLogo.png"));
    JLabel iconLabel = new JLabel(icon);
    iconLabel.setPreferredSize(new Dimension(icon.getIconWidth() + 40, icon.getIconHeight() + 40));

    Box textInputBox = new Box(BoxLayout.X_AXIS);
    textInputBox.add(new JLabel(nickname));
    textInputBox.add((textInput = new JTextField()));

    JPanel textPanel = new JPanel(new BorderLayout());
    textPanel.add((textScroller = new JScrollPane((textOutput = new JTextArea(7, 0)),
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED)),
            BorderLayout.CENTER);
    textPanel.add(textInputBox, BorderLayout.SOUTH);

    textOutput.setEditable(false);
    textInput.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String message = textInput.getText();
            textInput.setText("");
            try {
                ch.basicPublish(exchangeName, nickname, MessageProperties.TEXT_PLAIN, message.getBytes());
            } catch (IOException ioe) {
                System.err.println("IOException sending text message");
                ioe.printStackTrace();
            }
        }
    });

    JPanel main = new JPanel();
    main.setBackground(Color.WHITE);
    main.setLayout(new BorderLayout());
    main.add(iconLabel, BorderLayout.NORTH);
    main.add(componentPanel, BorderLayout.CENTER);
    main.add(textPanel, BorderLayout.SOUTH);

    frame.getContentPane().add(main);

}

From source file:org.openbaton.common.vnfm_sdk.amqp.AbstractVnfmSpringAmqp.java

License:Apache License

@Override
protected void unregister() {
    try {//from   w w w  .ja v  a2 s.  c  om
        ((VnfmSpringHelperRabbit) vnfmHelper).sendMessageToQueue(RabbitConfiguration.queueName_vnfmUnregister,
                vnfmManagerEndpoint);
    } catch (IllegalStateException e) {
        log.warn("Got exception while unregistering trying to do it manually");
        ConnectionFactory factory = new ConnectionFactory();

        factory.setHost(rabbitHost);
        Connection connection = null;
        try {
            connection = factory.newConnection();

            Channel channel = connection.createChannel();

            String message = gson.toJson(vnfmManagerEndpoint);
            channel.basicPublish("openbaton-exchange", RabbitConfiguration.queueName_vnfmUnregister,
                    MessageProperties.TEXT_PLAIN, message.getBytes("UTF-8"));
            log.debug("Sent '" + message + "'");

            channel.close();
            connection.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

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   www. jav  a2  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 w  w  .ja  v  a 2s.com*/
        throw new RuleException("Message Properties: '" + name + "' is undefined!");
    }
}

From source file:org.trpr.platform.integration.impl.messaging.RabbitMQMessagePublisherImpl.java

License:Apache License

/**
 * Publishes on a provided connection as per the connection configuration index. 
 * If the connection is null or if publishing fails it throws an Exception.
 * @param message//from  w  w w.  j  a  va 2  s.  c  om
 * @param connectionIndex
 * @throws Exception
 */
protected void publishToConnection(Object message, int connectionIndex) throws Exception {
    RabbitMQConfiguration rabbitMQConfiguration = rabbitMQConfigurations.get(connectionIndex);

    if (this.rabbitConnectionHolders[connectionIndex] == null) {
        throw new MessagingException("Connection not initialized");
    }

    boolean isMessageOfTypeString = (message instanceof String);
    byte[] body = isMessageOfTypeString ? ((String) message).getBytes(ENCODING)
            : PlatformUtils.toBytes(message);
    AMQP.BasicProperties msgProps = rabbitMQConfiguration.isDurable()
            ? (isMessageOfTypeString ? MessageProperties.PERSISTENT_TEXT_PLAIN
                    : MessageProperties.PERSISTENT_BASIC)
            : (isMessageOfTypeString ? MessageProperties.TEXT_PLAIN : MessageProperties.BASIC);

    if (rabbitMQConfiguration.isDurable()) {
        synchronized (this.rabbitConnectionHolders[connectionIndex].getChannel()) {
            // synchronized on the channel to avoid the below RabbitMQ client exception, caused in multi-threaded execution using the same channel:
            // java.lang.IllegalStateException: cannot execute more than one synchronous AMQP command at a time
            this.rabbitConnectionHolders[connectionIndex].getChannel().basicPublish(
                    rabbitMQConfiguration.getExchangeName(), rabbitMQConfiguration.getRoutingKey(), msgProps,
                    body);
            // Commit the message if it is durable and the commit count is reached. 
            // The channel should and would be in txSelect mode when it was created using the RabbitMQConfiguration details
            // increment totNoOfMessagesQueued by 1 and check as it is post incremented after publishing the message
            if ((totNoOfMessagesQueued + 1) % rabbitMQConfiguration.getDurableMessageCommitCount() == 0) {
                if (rabbitMQConfiguration.isDisableTX()) {
                    // error out, as explicitly disabling TX will not make the message durable
                    LOGGER.error(
                            "Configuration conflict. TX disabled for message publishing on durable queue. Message will not be published.");
                    return;
                }
                this.rabbitConnectionHolders[connectionIndex].getChannel().txCommit();
            }
        }
    } else {
        this.rabbitConnectionHolders[connectionIndex].getChannel().basicPublish(
                rabbitMQConfiguration.getExchangeName(), rabbitMQConfiguration.getRoutingKey(), msgProps, body);
    }
}

From source file:org.voltdb.bulkloader.RMQCSVSend.java

License:Open Source License

private static void sendMessages(RMQOptions rmqOpts, RandomSleeper.RSOptions sleeperOpts, TestOptions testOpts)
        throws InterruptedException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(rmqOpts.host);/*from  www  . ja v a2 s.c o m*/

    Connection connection = null;
    Channel channel = null;
    String exchangeName = "";
    // Use the queue name if the routing key is not specified.
    String routingKey = rmqOpts.routing != null ? rmqOpts.routing : rmqOpts.queue;
    try {
        connection = factory.newConnection();
        channel = connection.createChannel();
        if (rmqOpts.exchange != null) {
            exchangeName = rmqOpts.exchange;
            channel.exchangeDeclare(exchangeName, rmqOpts.extype);
        }
    } catch (IOException e1) {
        e1.printStackTrace();
        System.exit(255);
    }

    try {
        channel.queueDeclare(rmqOpts.queue, rmqOpts.persistent, false, false, null);
        try {
            while (testOpts.lineIter.hasNext()) {
                String message = testOpts.lineIter.next();
                channel.basicPublish(exchangeName, routingKey, MessageProperties.TEXT_PLAIN,
                        message.getBytes());
                System.out.printf(" [x] Sent '%s'\n", message);
                sleeperOpts.sleeper.sleep();
            }
        } finally {
            testOpts.lineIter.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            channel.close();
            connection.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}