List of usage examples for com.rabbitmq.client BasicProperties getUserId
public abstract String getUserId();
From source file:com.analogmountains.flume.RabbitMQSource.java
License:Open Source License
private Map<String, String> eventHeadersFromBasicProperties(BasicProperties properties) { Map<String, String> headers = new HashMap<String, String>(); if (properties.getAppId() != null) { headers.put("appId", properties.getAppId()); }/*from w w w . j a va 2 s . c o m*/ if (properties.getContentEncoding() != null) { headers.put("contentEncoding", properties.getContentEncoding()); } if (properties.getContentType() != null) { headers.put("contentType", properties.getContentType()); } if (properties.getCorrelationId() != null) { headers.put("correlationId", properties.getCorrelationId()); } if (properties.getDeliveryMode() != null) { headers.put("deliveryMode", Integer.toString(properties.getDeliveryMode())); } if (properties.getExpiration() != null) { headers.put("expiration", properties.getExpiration()); } if (properties.getMessageId() != null) { headers.put("messageId", properties.getMessageId()); } if (properties.getPriority() != null) { headers.put("priority", Integer.toString(properties.getPriority())); } if (properties.getReplyTo() != null) { headers.put("replyTo", properties.getReplyTo()); } if (properties.getType() != null) { headers.put("type", properties.getType()); } if (properties.getUserId() != null) { headers.put("userId", properties.getUserId()); } return headers; }
From source file:com.shopwiki.roger.MessagingUtil.java
License:Apache License
public static String prettyPrint(BasicProperties props) { StringBuilder sb = new StringBuilder(); sb.append("\t" + "ContentType: " + props.getContentType() + "\n"); sb.append("\t" + "ContentEncoding: " + props.getContentEncoding() + "\n"); sb.append("\t" + "Headers: " + props.getHeaders() + "\n"); sb.append("\t" + "DeliveryMode: " + props.getDeliveryMode() + "\n"); sb.append("\t" + "Priority: " + props.getPriority() + "\n"); sb.append("\t" + "CorrelationId: " + props.getCorrelationId() + "\n"); sb.append("\t" + "ReplyTo: " + props.getReplyTo() + "\n"); sb.append("\t" + "Expiration: " + props.getExpiration() + "\n"); sb.append("\t" + "MessageId: " + props.getMessageId() + "\n"); sb.append("\t" + "Timestamp: " + props.getTimestamp() + "\n"); sb.append("\t" + "Type: " + props.getType() + "\n"); sb.append("\t" + "UserId: " + props.getUserId() + "\n"); sb.append("\t" + "AppId: " + props.getAppId()); return sb.toString(); }
From source file:com.springsource.insight.plugin.rabbitmqClient.AbstractRabbitMQCollectionAspect.java
License:Apache License
protected void applyPropertiesData(Operation op, BasicProperties props) { OperationMap map = op.createMap("props"); map.putAnyNonEmpty("Type", props.getType()); map.putAnyNonEmpty("App Id", props.getAppId()); map.putAnyNonEmpty("User Id", props.getUserId()); map.put("Class Id", props.getClassId()); map.putAnyNonEmpty("Reply To", props.getReplyTo()); map.putAnyNonEmpty("Priority", props.getPriority()); map.putAnyNonEmpty("Class Name", props.getClassName()); map.putAnyNonEmpty("Timestamp", props.getTimestamp()); map.putAnyNonEmpty("Message Id", props.getMessageId()); map.putAnyNonEmpty("Expiration", props.getExpiration()); map.putAnyNonEmpty("Content Type", props.getContentType()); map.putAnyNonEmpty("Delivery Mode", props.getDeliveryMode()); map.putAnyNonEmpty("Correlation Id", props.getCorrelationId()); map.putAnyNonEmpty("Content Encoding", props.getContentEncoding()); Map<String, Object> headers = props.getHeaders(); if (headers != null) { OperationMap headersMap = op.createMap("headers"); for (Entry<String, Object> entry : headers.entrySet()) { Object value = entry.getValue(); if (value instanceof LongString) { byte[] bytes = ((LongString) value).getBytes(); value = new String(bytes); }/*from w w w .j a va2s.com*/ headersMap.putAnyNonEmpty(entry.getKey(), value); } } }
From source file:com.streamsets.pipeline.stage.origin.rabbitmq.RabbitSource.java
License:Apache License
@Override public String produce(String lastSourceOffset, int maxBatchSize, BatchMaker batchMaker) throws StageException { if (!isConnected() && !conf.advanced.automaticRecoveryEnabled) { // If we don't have automatic recovery enabled and the connection is closed, we should stop the pipeline. throw new StageException(Errors.RABBITMQ_05); }/*from w ww . ja va2 s . c o m*/ long maxTime = System.currentTimeMillis() + conf.basicConfig.maxWaitTime; int maxRecords = Math.min(maxBatchSize, conf.basicConfig.maxBatchSize); int numRecords = 0; String nextSourceOffset = lastSourceOffset; while (System.currentTimeMillis() < maxTime && numRecords < maxRecords) { try { RabbitMessage message = messages.poll(conf.basicConfig.maxWaitTime, TimeUnit.MILLISECONDS); if (message == null) { continue; } String recordId = message.getEnvelope().toString(); List<Record> records = parseRabbitMessage(recordId, message.getBody()); for (Record record : records) { Envelope envelope = message.getEnvelope(); BasicProperties properties = message.getProperties(); Record.Header outHeader = record.getHeader(); if (envelope != null) { setHeaderIfNotNull(outHeader, "deliveryTag", envelope.getDeliveryTag()); setHeaderIfNotNull(outHeader, "exchange", envelope.getExchange()); setHeaderIfNotNull(outHeader, "routingKey", envelope.getRoutingKey()); setHeaderIfNotNull(outHeader, "redelivered", envelope.isRedeliver()); } setHeaderIfNotNull(outHeader, "contentType", properties.getContentType()); setHeaderIfNotNull(outHeader, "contentEncoding", properties.getContentEncoding()); setHeaderIfNotNull(outHeader, "deliveryMode", properties.getDeliveryMode()); setHeaderIfNotNull(outHeader, "priority", properties.getPriority()); setHeaderIfNotNull(outHeader, "correlationId", properties.getCorrelationId()); setHeaderIfNotNull(outHeader, "replyTo", properties.getReplyTo()); setHeaderIfNotNull(outHeader, "expiration", properties.getExpiration()); setHeaderIfNotNull(outHeader, "messageId", properties.getMessageId()); setHeaderIfNotNull(outHeader, "timestamp", properties.getTimestamp()); setHeaderIfNotNull(outHeader, "messageType", properties.getType()); setHeaderIfNotNull(outHeader, "userId", properties.getUserId()); setHeaderIfNotNull(outHeader, "appId", properties.getAppId()); Map<String, Object> inHeaders = properties.getHeaders(); if (inHeaders != null) { for (Map.Entry<String, Object> pair : inHeaders.entrySet()) { // I am concerned about overlapping with the above headers but it seems somewhat unlikely // in addition the behavior of copying these attributes in with no custom prefix is // how the jms origin behaves setHeaderIfNotNull(outHeader, pair.getKey(), pair.getValue()); } } batchMaker.addRecord(record); nextSourceOffset = outHeader.getAttribute("deliveryTag"); numRecords++; } } catch (InterruptedException e) { LOG.warn("Pipeline is shutting down."); } } return nextSourceOffset; }
From source file:gash.router.server.MessageServer.java
License:Apache License
public void createQueue() throws IOException, ShutdownSignalException, ConsumerCancelledException, InterruptedException, SQLException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare("inbound_queue", false, false, false, null); channel.basicQos(1);/*from w w w .j av a 2 s . c o m*/ postgre = new PostgreSQL(url, username, password, dbname, ssl); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume("inbound_queue", false, consumer); // Map<String, byte[]> map = new HashMap<String, byte[]>(); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); BasicProperties props = delivery.getProperties(); String request = props.getType(); System.out.println(request); if (request != null) { if (request.equals("get")) { String key = new String(delivery.getBody()); BasicProperties replyProps = new BasicProperties.Builder() .correlationId(props.getCorrelationId()).build(); byte[] image = postgre.get(key); channel.basicPublish("", props.getReplyTo(), replyProps, image); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } if (request.equals("put")) { byte[] image = delivery.getBody(); postgre.put(props.getUserId(), image); BasicProperties replyProps = new BasicProperties.Builder() .correlationId(props.getCorrelationId()).build(); channel.basicPublish("", props.getReplyTo(), replyProps, image); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } if (request.equals("post")) { System.out.println("Message Server"); String key = postgre.post(delivery.getBody()); BasicProperties replyProps = new BasicProperties.Builder() .correlationId(props.getCorrelationId()).build(); channel.basicPublish("", props.getReplyTo(), replyProps, key.getBytes()); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } if (request.equals("delete")) { String key = new String(delivery.getBody()); postgre.delete(key); } } } }
From source file:net.echinopsii.ariane.community.messaging.rabbitmq.MsgTranslator.java
License:Open Source License
/** * Decode given Message into Map message * @param message a RabbitMQ friendly message * @return Map message/*from w ww.j a v a 2s.c o m*/ */ @Override public Map<String, Object> decode(Message message) { Envelope envelope = message.getEnvelope(); BasicProperties properties = (BasicProperties) message.getProperties(); byte[] body = message.getBody(); LinkedHashMap<String, Object> decodedMessage = new LinkedHashMap<String, Object>(); if (envelope != null) { decodedMessage.put(MSG_RBQ_DELIVERY_TAG, envelope.getDeliveryTag()); decodedMessage.put(MSG_RBQ_EXCHANGE, envelope.getExchange()); decodedMessage.put(MSG_RBQ_ROUTINGKEY, envelope.getRoutingKey()); } if (properties != null) { decodedMessage.put(MSG_APPLICATION_ID, properties.getAppId()); decodedMessage.put(MSG_RBQ_CONTENT_ENCODING, properties.getContentEncoding()); decodedMessage.put(MSG_RBQ_CONTENT_TYPE, properties.getContentType()); decodedMessage.put(MSG_CORRELATION_ID, properties.getCorrelationId()); decodedMessage.put(MSG_DELIVERY_MODE, properties.getDeliveryMode()); decodedMessage.put(MSG_EXPIRATION, properties.getExpiration()); decodedMessage.put(MSG_MESSAGE_ID, properties.getMessageId()); decodedMessage.put(MSG_PRIORITY, properties.getPriority()); decodedMessage.put(MSG_REPLY_TO, properties.getReplyTo()); decodedMessage.put(MSG_TIMESTAMP, properties.getTimestamp()); decodedMessage.put(MSG_TYPE, properties.getType()); decodedMessage.put(MSG_RBQ_USER_ID, properties.getUserId()); Map<String, Object> headerFields = properties.getHeaders(); if (headerFields != null) { for (String key : headerFields.keySet()) if (headerFields.get(key) != null) { if (headerFields.get(key) instanceof LongString) decodedMessage.put(key, headerFields.get(key).toString()); else decodedMessage.put(key, headerFields.get(key)); } else decodedMessage.put(key, headerFields.get(key)); } } if (body.length == 0) decodedMessage.put(MSG_BODY, null); else decodedMessage.put(MSG_BODY, body); return decodedMessage; }
From source file:org.mule.transport.amqp.AmqpMuleMessageFactory.java
License:Open Source License
private void addBasicProperties(final DefaultMuleMessage muleMessage, final Map<String, Object> messageProperties, final BasicProperties amqpProperties) { if (amqpProperties == null) return;/* w ww . j a v a 2 s . c o m*/ putIfNonNull(messageProperties, AmqpConstants.APP_ID, amqpProperties.getAppId()); putIfNonNull(messageProperties, AmqpConstants.CONTENT_ENCODING, amqpProperties.getContentEncoding()); putIfNonNull(messageProperties, AmqpConstants.CONTENT_TYPE, amqpProperties.getContentType()); final String correlationId = amqpProperties.getCorrelationId(); putIfNonNull(messageProperties, AmqpConstants.CORRELATION_ID, correlationId); putIfNonNull(messageProperties, MuleProperties.MULE_CORRELATION_ID_PROPERTY, correlationId); muleMessage.setCorrelationId(correlationId); putIfNonNull(messageProperties, AmqpConstants.DELIVERY_MODE, amqpProperties.getDeliveryMode()); putIfNonNull(messageProperties, AmqpConstants.EXPIRATION, amqpProperties.getExpiration()); final String messageId = amqpProperties.getMessageId(); putIfNonNull(messageProperties, AmqpConstants.MESSAGE_ID, messageId); putIfNonNull(messageProperties, MuleProperties.MULE_MESSAGE_ID_PROPERTY, messageId); muleMessage.setUniqueId(messageId); putIfNonNull(messageProperties, AmqpConstants.PRIORITY, amqpProperties.getPriority()); final String replyTo = amqpProperties.getReplyTo(); putIfNonNull(messageProperties, AmqpConstants.REPLY_TO, replyTo); muleMessage.setReplyTo(replyTo); putIfNonNull(messageProperties, AmqpConstants.TIMESTAMP, amqpProperties.getTimestamp()); putIfNonNull(messageProperties, AmqpConstants.TYPE, amqpProperties.getType()); putIfNonNull(messageProperties, AmqpConstants.USER_ID, amqpProperties.getUserId()); messageProperties.putAll(amqpProperties.getHeaders()); }
From source file:org.mule.transport.amqp.AmqpMuleMessageFactoryTestCase.java
License:Open Source License
public static void checkInboundProperties(final AmqpMessage amqpMessage, final MuleMessage muleMessage) { assertEquals(amqpMessage.getConsumerTag(), muleMessage.getProperty(AmqpConstants.CONSUMER_TAG, PropertyScope.INBOUND)); final Envelope envelope = amqpMessage.getEnvelope(); assertEquals(envelope.getDeliveryTag(), muleMessage.getProperty(AmqpConstants.DELIVERY_TAG, PropertyScope.INBOUND)); assertEquals(envelope.isRedeliver(), muleMessage.getProperty(AmqpConstants.REDELIVER, PropertyScope.INBOUND)); assertEquals(envelope.getExchange(), muleMessage.getProperty(AmqpConstants.EXCHANGE, PropertyScope.INBOUND)); assertEquals(envelope.getRoutingKey(), muleMessage.getProperty(AmqpConstants.ROUTING_KEY, PropertyScope.INBOUND)); final BasicProperties amqpProperties = amqpMessage.getProperties(); assertEquals(amqpProperties.getAppId(), muleMessage.getProperty(AmqpConstants.APP_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getContentEncoding(), muleMessage.getProperty(AmqpConstants.CONTENT_ENCODING, PropertyScope.INBOUND)); assertEquals(amqpProperties.getContentType(), muleMessage.getProperty(AmqpConstants.CONTENT_TYPE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getCorrelationId(), muleMessage.getProperty(AmqpConstants.CORRELATION_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getCorrelationId(), muleMessage.getCorrelationId()); assertEquals(amqpProperties.getDeliveryMode(), muleMessage.getProperty(AmqpConstants.DELIVERY_MODE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getExpiration(), muleMessage.getProperty(AmqpConstants.EXPIRATION, PropertyScope.INBOUND)); assertEquals(amqpProperties.getMessageId(), muleMessage.getProperty(AmqpConstants.MESSAGE_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getMessageId(), muleMessage.getUniqueId()); assertEquals(amqpProperties.getPriority(), muleMessage.getProperty(AmqpConstants.PRIORITY, PropertyScope.INBOUND)); assertEquals(amqpProperties.getReplyTo(), muleMessage.getProperty(AmqpConstants.REPLY_TO, PropertyScope.INBOUND)); assertEquals(amqpProperties.getReplyTo(), muleMessage.getReplyTo()); assertEquals(amqpProperties.getTimestamp(), muleMessage.getProperty(AmqpConstants.TIMESTAMP, PropertyScope.INBOUND)); assertEquals(amqpProperties.getType(), muleMessage.getProperty(AmqpConstants.TYPE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getUserId(), muleMessage.getProperty(AmqpConstants.USER_ID, PropertyScope.INBOUND)); for (final Entry<String, Object> header : amqpProperties.getHeaders().entrySet()) { assertEquals(header.getValue(), muleMessage.getProperty(header.getKey(), PropertyScope.INBOUND)); }//from w w w . j a va 2 s. co m }
From source file:org.mule.transport.amqp.internal.domain.AmqpMuleMessageFactory.java
License:Open Source License
private void addBasicProperties(final BasicProperties amqpProperties, final DefaultMuleMessage muleMessage, final Map<String, Object> messageProperties) { if (amqpProperties == null) return;/*from w w w . j a va 2 s.c om*/ putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_APP_ID, amqpProperties.getAppId(), messageProperties); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CONTENT_ENCODING, amqpProperties.getContentEncoding(), messageProperties); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CONTENT_TYPE, amqpProperties.getContentType(), messageProperties); final String correlationId = amqpProperties.getCorrelationId(); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CORRELATION_ID, correlationId, messageProperties); putIfNonNull(MuleProperties.MULE_CORRELATION_ID_PROPERTY, correlationId, messageProperties); muleMessage.setCorrelationId(correlationId); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_MODE, amqpProperties.getDeliveryMode(), messageProperties); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_EXPIRATION, amqpProperties.getExpiration(), messageProperties); final String messageId = amqpProperties.getMessageId(); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_MESSAGE_ID, messageId, messageProperties); putIfNonNull(MuleProperties.MULE_MESSAGE_ID_PROPERTY, messageId, messageProperties); muleMessage.setUniqueId(messageId == null ? UUID.getUUID() : messageId); final String clusterId = amqpProperties.getClusterId(); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CLUSTER_ID, clusterId, messageProperties); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_PRIORITY, amqpProperties.getPriority(), messageProperties); final String replyTo = amqpProperties.getReplyTo(); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_REPLY_TO, replyTo, messageProperties); muleMessage.setReplyTo(replyTo); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_TIMESTAMP, amqpProperties.getTimestamp(), messageProperties); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_TYPE, amqpProperties.getType(), messageProperties); putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_USER_ID, amqpProperties.getUserId(), messageProperties); }
From source file:org.mule.transport.amqp.internal.domain.AmqpMuleMessageFactoryTestCase.java
License:Open Source License
public static void checkInboundProperties(final AmqpMessage amqpMessage, final MuleMessage muleMessage) { assertEquals(amqpMessage.getConsumerTag(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONSUMER_TAG, PropertyScope.INBOUND)); final Envelope envelope = amqpMessage.getEnvelope(); assertEquals(envelope.getDeliveryTag(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_TAG, PropertyScope.INBOUND)); assertEquals(envelope.isRedeliver(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_REDELIVER, PropertyScope.INBOUND)); assertEquals(envelope.getExchange(), muleMessage.getProperty(AmqpConnector.EXCHANGE, PropertyScope.INBOUND)); assertEquals(envelope.getRoutingKey(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_ROUTING_KEY, PropertyScope.INBOUND)); final BasicProperties amqpProperties = amqpMessage.getProperties(); assertEquals(amqpProperties.getAppId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_APP_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getContentEncoding(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONTENT_ENCODING, PropertyScope.INBOUND)); assertEquals(amqpProperties.getContentType(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONTENT_TYPE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getClusterId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CLUSTER_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getCorrelationId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CORRELATION_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getCorrelationId(), muleMessage.getCorrelationId()); assertEquals(amqpProperties.getDeliveryMode(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_MODE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getExpiration(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_EXPIRATION, PropertyScope.INBOUND)); assertEquals(amqpProperties.getMessageId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_MESSAGE_ID, PropertyScope.INBOUND)); assertEquals(amqpProperties.getMessageId(), muleMessage.getUniqueId()); assertEquals(amqpProperties.getPriority(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_PRIORITY, PropertyScope.INBOUND)); assertEquals(amqpProperties.getReplyTo(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_REPLY_TO, PropertyScope.INBOUND)); assertEquals(amqpProperties.getReplyTo(), muleMessage.getReplyTo()); assertEquals(amqpProperties.getTimestamp(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_TIMESTAMP, PropertyScope.INBOUND)); assertEquals(amqpProperties.getType(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_TYPE, PropertyScope.INBOUND)); assertEquals(amqpProperties.getUserId(), muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_USER_ID, PropertyScope.INBOUND)); for (final Entry<String, Object> header : amqpProperties.getHeaders().entrySet()) { assertEquals(header.getValue(), muleMessage.getProperty(header.getKey(), PropertyScope.INBOUND)); }// w w w . j ava 2s.c o m }