Example usage for com.rabbitmq.client MessageProperties BASIC

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

Introduction

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

Prototype

BasicProperties BASIC

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

Click Source Link

Document

Content-type "application/octet-stream", deliveryMode 1 (nonpersistent), priority zero

Usage

From source file:com.ericsson.eiffel.remrem.publish.helper.RabbitMqProperties.java

License:Apache License

/**
 * This method is used to publish the message to RabbitMQ
 * @param routingKey//from   w  w w.  j  av  a 2 s .c  o m
 * @param msg is Eiffel Event
 * @throws IOException
 */
public void send(String routingKey, String msg) throws IOException {

    Channel channel = giveMeRandomChannel();
    channel.addShutdownListener(new ShutdownListener() {
        public void shutdownCompleted(ShutdownSignalException cause) {
            // Beware that proper synchronization is needed here
            if (cause.isInitiatedByApplication()) {
                log.debug("Shutdown is initiated by application. Ignoring it.");
            } else {
                log.error("Shutdown is NOT initiated by application.");
                log.error(cause.getMessage());
                boolean cliMode = Boolean.getBoolean(PropertiesConfig.CLI_MODE);
                if (cliMode) {
                    System.exit(-3);
                }
            }
        }
    });

    BasicProperties msgProps = MessageProperties.BASIC;
    if (usePersitance)
        msgProps = MessageProperties.PERSISTENT_BASIC;

    channel.basicPublish(exchangeName, routingKey, msgProps, msg.getBytes());
    log.info("Published message with size {} bytes on exchange '{}' with routing key '{}'",
            msg.getBytes().length, exchangeName, routingKey);
}

From source file:com.kumuluz.ee.samples.amqp.rabbitmq.messaging.MessageProducer.java

License:MIT License

@AMQPProducer(host = "MQtest2", key = "testQueue")
public Message sendToQueue() {
    Message message = new Message();
    ExampleObject exampleObject = new ExampleObject();
    exampleObject.setContent("I'm an object in a message");
    return message.body(exampleObject).basicProperties(MessageProperties.BASIC);
}

From source file:com.kumuluz.ee.samples.amqp.rabbitmq.messaging.MessageProducer.java

License:MIT License

@AMQPProducer
public Message sendFullMessage() {
    Message message = new Message();
    ExampleObject exampleObject = new ExampleObject();
    exampleObject.setContent("I'm an object in a special message");

    if (Math.random() < 0.5) {
        message.host("MQtest").key(new String[] { "object" }).exchange("directExchange")
                .basicProperties(MessageProperties.BASIC);
    } else {//www .j  ava  2  s . c  om
        message.host("MQtest2").key(new String[] { "testQueue" }).basicProperties("testProperty");
    }

    return message.body(exampleObject);
}

From source file:org.apache.camel.component.rabbitmq.RabbitMQConfigurationTest.java

License:Apache License

@Test
public void createEndpointWithMessageProperties() throws Exception {
    RabbitMQComponent component = new RabbitMQComponent(context);
    RabbitMQEndpoint endpoint = (RabbitMQEndpoint) component
            .createEndpoint(BASIC_URI + "?messageProperties=BASIC");

    RabbitMQConfiguration config = endpoint.getConfiguration();
    assertEquals(MessageProperties.BASIC, config.getMessageProperties());
    checkBaseConfig(config);// ww  w  .ja v  a 2s  .  com

}

From source file:org.elasticsoftware.elasticactors.rabbitmq.cpt.LocalMessageQueue.java

License:Apache License

private AMQP.BasicProperties createProps(InternalMessage message) {
    if (message.getTimeout() < 0) {
        return message.isDurable() ? MessageProperties.PERSISTENT_BASIC : MessageProperties.BASIC;
    } else {//from  w w w  . j a va2  s  .  co  m
        if (message.isDurable()) {
            return new AMQP.BasicProperties.Builder().contentType("application/octet-stream").deliveryMode(2)
                    .priority(0).expiration(String.valueOf(message.getTimeout())).build();
        } else {
            return new AMQP.BasicProperties.Builder().contentType("application/octet-stream").deliveryMode(1)
                    .priority(0).expiration(String.valueOf(message.getTimeout())).build();
        }
    }
}

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:/* w  w  w. j ava  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  ww w  . j a v  a2 s. c om
        throw new RuleException("Message Properties: '" + name + "' is undefined!");
    }
}

From source file:org.trpr.mule.transport.rabbitmq.RabbitDispatcher.java

License:Apache License

/**
 * Abstract method implementation. Dispatches the specified MuleEvent using the RPC client
 * @see org.mule.transport.AbstractMessageDispatcher#doDispatch(org.mule.api.MuleEvent)
 *//*ww  w .  ja  v  a  2  s  .c  o  m*/
protected void doDispatch(MuleEvent event) throws Exception {
    MuleMessage msg = event.getMessage();
    AMQP.BasicProperties msgProps = EndpointUtils.getDurable(endpoint) ? MessageProperties.PERSISTENT_BASIC
            : MessageProperties.BASIC;
    rpcClient.publish(msgProps, msg.getPayloadAsBytes());
    dispatchedMessageCount++;
    // commit the message if the endpoint is durable and the commit count is reached. 
    // The channel should and would have been created with txSelect in the RabbitConnector
    if (EndpointUtils.getDurable(endpoint)
            && (dispatchedMessageCount % ((RabbitConnector) connector).getDurableMessageCommitCount() == 0)) {
        // 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
        synchronized (channel) {
            channel.txCommit();
        }
    }
}

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//www  .  j ava2  s  .c  o m
 * @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);
    }
}