List of usage examples for com.rabbitmq.client BasicProperties getContentEncoding
public abstract String getContentEncoding();
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 . ja 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 va 2 s. c o m headersMap.putAnyNonEmpty(entry.getKey(), value); } } }
From source file:com.springsource.insight.plugin.rabbitmqClient.AbstractRabbitMQCollectionAspectTestSupport.java
License:Open Source License
protected Operation assertBasicOperation(Operation op, BasicProperties props, byte[] body, String opLabel) { assertEquals("Mismatched body length", ArrayUtil.length(body), op.getInt("bytes", (-1))); assertEquals("Mismatched label", opLabel, op.getLabel()); for (String propName : new String[] { "connectionUrl", "serverVersion", "clientVersion" }) { assertNullValue(propName, op.get(propName)); }//from w w w .ja v a 2 s . co m OperationMap propsMap = op.get("props", OperationMap.class); assertNotNull("No properties extracted", propsMap); assertEquals("Mismatched application ID", props.getAppId(), propsMap.get("App Id")); assertEquals("Mismatched content encoding", props.getContentEncoding(), propsMap.get("Content Encoding")); assertEquals("Mismatched content type", props.getContentType(), propsMap.get("Content Type")); assertEquals("Mismatched delivery mode", props.getDeliveryMode().intValue(), propsMap.getInt("Delivery Mode", (-1))); assertEquals("Mismatched expiration", props.getExpiration(), propsMap.get("Expiration")); return op; }
From source file:com.springsource.insight.plugin.rabbitmqClient.RabbitMQConsumerCollectionAspectTest.java
License:Apache License
void assertOperation(Envelope envelope, BasicProperties props, byte[] body) { Operation op = getLastEntered(); assertEquals(OperationType.valueOf("rabbitmq-client-consumer"), op.getType()); assertEquals("Consume", op.getLabel()); assertEquals(Integer.valueOf(body.length), op.get("bytes", Integer.class)); OperationMap envMap = op.get("envelope", OperationMap.class); assertNotNull(envMap);//from w ww . ja v a 2s .c om assertEquals(Long.valueOf(envelope.getDeliveryTag()), envMap.get("deliveryTag", Long.class)); assertEquals(envelope.getExchange(), envMap.get("exchange", String.class)); assertEquals(envelope.getRoutingKey(), envMap.get("routingKey", String.class)); assertNull(op.get("connectionUrl")); assertNull(op.get("serverVersion")); assertNull(op.get("clientVersion")); OperationMap propsMap = op.get("props", OperationMap.class); assertEquals(props.getAppId(), propsMap.get("App Id")); assertEquals(props.getContentEncoding(), propsMap.get("Content Encoding")); assertEquals(props.getContentType(), propsMap.get("Content Type")); assertEquals(props.getDeliveryMode(), propsMap.get("Delivery Mode")); assertEquals(props.getExpiration(), propsMap.get("Expiration")); }
From source file:com.springsource.insight.plugin.rabbitmqClient.RabbitMQPublishCollectionAspectTest.java
License:Apache License
void assertOperation(Operation op, BasicProperties props, byte[] body) { assertEquals(OperationType.valueOf("rabbitmq-client-publish"), op.getType()); assertEquals("Publish", op.getLabel()); assertEquals(Integer.valueOf(body.length), op.get("bytes", Integer.class)); assertNull(op.get("connectionUrl")); assertNull(op.get("serverVersion")); assertNull(op.get("clientVersion")); OperationMap propsMap = op.get("props", OperationMap.class); assertEquals(props.getAppId(), propsMap.get("App Id")); assertEquals(props.getContentEncoding(), propsMap.get("Content Encoding")); assertEquals(props.getContentType(), propsMap.get("Content Type")); assertEquals(props.getDeliveryMode(), propsMap.get("Delivery Mode")); assertEquals(props.getExpiration(), propsMap.get("Expiration")); }
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); }// www.j a v a 2s . c om 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:flens.input.AMQPInput.java
License:Apache License
@Override public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { Map<String, Object> fields = new HashMap<String, Object>(); fields.put("tag", consumerTag); fields.put("body", body); fields.put("mine-type", properties.getContentEncoding()); Date time = properties.getTimestamp(); long timel = time == null ? System.currentTimeMillis() : time.getTime(); Record r = Record.createWithTimeAndValues(timel, fields); dispatch(r);/* w w w .java2s. c o m*/ }
From source file:io.ventu.rpc.amqp.AmqpInvokerimplTest.java
License:MIT License
@Test public void invoke_onOkRequest_correctDataPassedToPublisher() throws IOException, TimeoutException, ExecutionException, InterruptedException { String instanceId = "123456789"; Req req = new Req(); Map<String, Object> headers = Maps.newHashMap(); headers.put("key", Integer.valueOf(12341234)); Channel channel = mock(Channel.class); doAnswer(invocation -> {//from ww w. j av a2 s. c om assertEquals(DEFAULT_RPC_EXCHANGE, invocation.getArguments()[0]); assertEquals(Req.class.getName(), invocation.getArguments()[1]); BasicProperties props = (BasicProperties) invocation.getArguments()[2]; assertEquals(instanceId, props.getAppId()); assertEquals(instanceId, props.getReplyTo()); assertEquals(CONTENT_TYPE, props.getContentType()); assertEquals(headers.get("key"), props.getHeaders().get("key")); assertEquals(ENCODING, props.getContentEncoding()); String actual = new String((byte[]) invocation.getArguments()[3]); assertEquals(new String(serializer.encode(req)), actual); return null; }).when(channel).basicPublish(anyString(), any(), any(), any()); CompletableFuture<Res> answer = new CompletableFuture<>(); ResponseReceiver receiver = mock(ResponseReceiver.class); doReturn(answer).when(receiver).put(anyString(), any()); ChannelProvider channelProvider = mock(ChannelProvider.class); doReturn(channel).when(channelProvider).provide(instanceId, receiver); doReturn(DEFAULT_RPC_EXCHANGE).when(channelProvider).rpcExchange(); RemoteInvoker invoker = new AmqpInvokerImpl(instanceId, channelProvider, receiver, new DefaultRequestRouter(), new UidGenerator() { }, serializer, headers); invoker.invoke(req, Res.class); // make sure it was invoked, otherwise our assertions will be void verify(channel).basicPublish(anyString(), any(), any(), any()); }
From source file:io.ventu.rpc.amqp.AmqpResponderImplTest.java
License:MIT License
@Test public void handleDeliveryInternal_responsePayloadPublished() throws TimeoutException, IOException, EncodingException, ExecutionException, InterruptedException { String routingKeyPattern = "routingKeyPattern"; String correlationId = "123456789"; Channel channel = mock(Channel.class); ChannelProvider provider = mock(ChannelProvider.class); doReturn("replyExchange").when(provider).rpcExchange(); doReturn(channel).when(provider).provide(anyString(), any()); Map<String, Object> headers = Maps.newHashMap(); headers.put("apikey", "234435345345"); final List<Boolean> invocations = Lists.newArrayList(); final CompletableFuture<byte[]> promise = new CompletableFuture<>(); AmqpResponderImpl responder = new AmqpResponderImpl(provider, routingKeyPattern) { @Override// w w w. ja v a2 s. c om <RQ, RS> CompletableFuture<byte[]> handleDelivery(String routingKey, Map<String, Object> actualHeaders, byte[] payload) { invocations.add(Boolean.TRUE); assertEquals(Req.class.getName(), routingKey); assertEquals("ABC", new String(payload)); assertEquals(headers.get("apikey"), actualHeaders.get("apikey")); promise.complete("CBA".getBytes()); return promise; } }; Envelope env = new Envelope(1L, false, "incomingEexchange", Req.class.getName()); BasicProperties props = new Builder().correlationId(correlationId).replyTo("replyHere").headers(headers) .build(); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { invocations.add(Boolean.TRUE); assertEquals("replyExchange", invocation.getArguments()[0]); assertEquals("replyHere", invocation.getArguments()[1]); BasicProperties respProps = (BasicProperties) invocation.getArguments()[2]; assertEquals(correlationId, respProps.getCorrelationId()); assertEquals(CONTENT_TYPE, respProps.getContentType()); assertEquals(ENCODING, respProps.getContentEncoding()); assertEquals("CBA", new String((byte[]) invocation.getArguments()[3])); return null; } }).when(channel).basicPublish(anyString(), anyString(), any(), any()); responder.handleDeliveryInternal("consumerTag", env, props, "ABC".getBytes()).get(1, TimeUnit.SECONDS); verify(channel).basicPublish(anyString(), anyString(), any(), any()); verifyNoMoreInteractions(channel); assertEquals(2, invocations.size()); }