Refine search
public Message request(Message message, long timeout, TimeUnit timeUnit) { Map<String, Object> properties = new HashMap<>(); if (message.getApplicationProperties() != null) { properties.putAll(message.getApplicationProperties().getValue()); } message.setApplicationProperties(new ApplicationProperties(properties)); if (message.getReplyTo() == null) { message.setReplyTo(replyTo); } context.runOnContext(h -> sender.send(message)); try { return replies.poll(timeout, timeUnit); } catch (InterruptedException e) { throw new RuntimeException(e); } }
private Map<String, Object> getApplicationPropertiesMap() { ApplicationProperties appMap = getApplicationProperties(); Map<String, Object> map = null; if (appMap != null) { map = appMap.getValue(); } if (map == null) { map = new HashMap<>(); this.applicationProperties = new ApplicationProperties(map); } return map; }
/** * Adds a property to an AMQP 1.0 message. * <p> * The property is added to the message's <em>application-properties</em>. * * @param msg The message. * @param key The property key. * @param value The property value. * @throws NullPointerException if any of th parameters are {@code null}. */ public static void addProperty(final Message msg, final String key, final Object value) { Objects.requireNonNull(msg); Objects.requireNonNull(key); Objects.requireNonNull(value); final ApplicationProperties props = Optional.ofNullable(msg.getApplicationProperties()) .orElseGet(() -> { final ApplicationProperties result = new ApplicationProperties(new HashMap<String, Object>()); msg.setApplicationProperties(result); return result; }); props.getValue().put(key, value); }
final ApplicationProperties applicationProperties = new ApplicationProperties(this.properties); amqpMessage.setApplicationProperties(applicationProperties); switch (propertyName) { case AmqpConstants.AMQP_PROPERTY_MESSAGE_ID: amqpMessage.setMessageId(systemProperty.getValue()); break; case AmqpConstants.AMQP_PROPERTY_USER_ID: amqpMessage.setUserId((byte[]) systemProperty.getValue()); break; case AmqpConstants.AMQP_PROPERTY_TO: final MessageAnnotations messageAnnotations = (amqpMessage.getMessageAnnotations() == null) ? new MessageAnnotations(new HashMap<>()) : amqpMessage.getMessageAnnotations(); messageAnnotations.getValue().put(Symbol.getSymbol(systemProperty.getKey()), systemProperty.getValue()); amqpMessage.setMessageAnnotations(messageAnnotations);
final Map<Symbol, Object> messageAnnotations = amqpMessage.getMessageAnnotations().getValue(); final HashMap<String, Object> receiveProperties = new HashMap<>(); if (amqpMessage.getProperties() != null) { if (amqpMessage.getMessageId() != null) receiveProperties.put(AmqpConstants.AMQP_PROPERTY_MESSAGE_ID, amqpMessage.getMessageId()); if (amqpMessage.getUserId() != null) this.properties = amqpMessage.getApplicationProperties() == null ? null : amqpMessage.getApplicationProperties().getValue(); final Section bodySection = amqpMessage.getBody();
protected void populateMessage(Message jms, org.apache.qpid.proton.message.Message amqp) throws Exception { Header header = amqp.getHeader(); if( header==null ) { header = new Header(); final DeliveryAnnotations da = amqp.getDeliveryAnnotations(); if( da!=null ) { for (Map.Entry<?,?> entry : da.getValue().entrySet()) { Class<? extends Destination> replyToAttributes = Destination.class; final MessageAnnotations ma = amqp.getMessageAnnotations(); if( ma!=null ) { for (Map.Entry<?,?> entry : ma.getValue().entrySet()) { String key = entry.getKey().toString(); if( "x-opt-jms-type".equals(key.toString()) && entry.getValue() != null ) { final ApplicationProperties ap = amqp.getApplicationProperties(); if( ap !=null ) { for (Map.Entry entry : (Set<Map.Entry>)ap.getValue().entrySet()) { String key = entry.getKey().toString(); if( "JMSXGroupID".equals(key) ) {
public static Message convertAmqpMessageToBrokeredMessage(org.apache.qpid.proton.message.Message amqpMessage, byte[] deliveryTag) Section body = amqpMessage.getBody(); if(body != null) ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties(); if(applicationProperties != null) brokeredMessage.setProperties(applicationProperties.getValue()); brokeredMessage.setTimeToLive(Duration.ofMillis(amqpMessage.getTtl())); brokeredMessage.setDeliveryCount(amqpMessage.getDeliveryCount()); if(messageAnnotations != null) Map<Symbol, Object> messageAnnotationsMap = messageAnnotations.getValue(); if(messageAnnotationsMap != null)
MessageAnnotations messageAnnotations = message.getMessageAnnotations(); if (messageAnnotations == null) { if (message.getHeader() != null) { qos = ((message.getHeader().getDurable() == null) || !message.getHeader().getDurable()) ? MqttQoS.AT_MOST_ONCE : MqttQoS.AT_LEAST_ONCE; if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_RETAIN_ANNOTATION))) { isRetain = (boolean) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_RETAIN_ANNOTATION)); if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_QOS_ANNOTATION))) { int value = (int) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_QOS_ANNOTATION)); qos = MqttQoS.valueOf(value); if (applicationProperties != null) { Object amqOrigAddress = applicationProperties.getValue().get("_AMQ_ORIG_ADDRESS"); topic = (amqOrigAddress != null) ? amqOrigAddress.toString() : topic;
if (message.getMessageId() != null) jsonProperties.put(AmqpJsonMessageConverter.MESSAGE_ID, message.getMessageId()); if (message.getAddress() != null) jsonProperties.put(AmqpJsonMessageConverter.TO, message.getAddress()); if (message.getSubject() != null) Map<String, Object> applicationPropertiesMap = (Map<String, Object>)applicationProperties.getValue(); for (Entry<String, Object> entry : applicationPropertiesMap.entrySet()) { partition = messageAnnotations.getValue().get(Symbol.getSymbol(AmqpBridge.AMQP_PARTITION_ANNOTATION)); key = messageAnnotations.getValue().get(Symbol.getSymbol(AmqpBridge.AMQP_KEY_ANNOTATION)); Map<Symbol, Object> messageAnnotationsMap = (Map<Symbol, Object>)messageAnnotations.getValue(); for (Entry<Symbol, Object> entry : messageAnnotationsMap.entrySet()) {
amqpMessage.setBody(new AmqpValue(body.getValueData())); amqpMessage.setBody(new AmqpSequence(Utils.getSequenceFromMessageBody(body))); amqpMessage.setBody(new Data(new Binary(Utils.getDataFromMessageBody(body)))); amqpMessage.setApplicationProperties(new ApplicationProperties(brokeredMessage.getProperties())); amqpMessage.setMessageAnnotations(new MessageAnnotations(messageAnnotationsMap));
message.setAddress(address); message.setMessageId(entry.getValue()); } else if (entry.getKey().equals(AmqpJsonMessageConverter.TO)) { message.setAddress(entry.getValue().toString()); } else if (entry.getKey().equals(AmqpJsonMessageConverter.SUBJECT)) { message.setSubject(entry.getValue().toString()); ApplicationProperties applicationProperties = new ApplicationProperties(applicationPropertiesMap); message.setApplicationProperties(applicationProperties); MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap); message.setMessageAnnotations(messageAnnotations);
@Override public List<String> getQueueNames(AmqpClient queueClient, Destination replyQueue, String topic) throws Exception { Message requestMessage = Message.Factory.create(); Map<String, Object> appProperties = new HashMap<>(); appProperties.put(resourceProperty, "address." + topic); appProperties.put(operationProperty, "getQueueNames"); requestMessage.setAddress(managementAddress); requestMessage.setApplicationProperties(new ApplicationProperties(appProperties)); requestMessage.setReplyTo(replyQueue.getAddress()); requestMessage.setBody(new AmqpValue("[]")); Future<Integer> sent = queueClient.sendMessages(managementAddress, requestMessage); assertThat(String.format("Sender failed, expected %d messages", 1), sent.get(30, TimeUnit.SECONDS), is(1)); log.info("request sent"); Future<List<Message>> received = queueClient.recvMessages(replyQueue.getAddress(), 1); assertThat(String.format("Receiver failed, expected %d messages", 1), received.get(30, TimeUnit.SECONDS).size(), is(1)); AmqpValue val = (AmqpValue) received.get().get(0).getBody(); log.info("answer received: " + val.toString()); String queues = val.getValue().toString(); queues = queues.replaceAll("\\[|]|\"", ""); return Arrays.asList(queues.split(",")); }
message.setMessageId(UUID.randomUUID().toString()); message.setCorrelationId(correlationId); message.setAddress(address.toString()); map.put(MessageHelper.APP_PROPERTY_CACHE_CONTROL, cacheDirective); message.setApplicationProperties(new ApplicationProperties(map)); message.setMessageAnnotations(new MessageAnnotations(annotations));
/** * Creates a new AmqpMessage that wraps the information necessary to handle * an incoming delivery. * * @param receiver the AmqpReceiver that received this message. * @param message the Proton message that was received. * @param delivery the Delivery instance that produced this message. */ @SuppressWarnings("unchecked") public AmqpMessage(AmqpReceiver receiver, Message message, Delivery delivery) { this.receiver = receiver; this.message = message; this.delivery = delivery; if (message.getMessageAnnotations() != null) { messageAnnotationsMap = message.getMessageAnnotations().getValue(); } if (message.getApplicationProperties() != null) { applicationPropertiesMap = message.getApplicationProperties().getValue(); } if (message.getDeliveryAnnotations() != null) { deliveryAnnotationsMap = message.getDeliveryAnnotations().getValue(); } }
msg.decode(data, 0, data.length); } catch(BufferOverflowException | BufferUnderflowException | DecodeException e) { malformedReason = MalformedDelivery.MalformedReason.PAYLOADNOTAMQP; Object msgBodyValue = ((AmqpValue)msg.getBody()).getValue(); if (msgBodyValue instanceof Binary) { Binary binaryValue = (Binary)msgBodyValue; payloadIsJson = "application/json".equalsIgnoreCase(msg.getContentType()); } else { malformedReason = MalformedDelivery.MalformedReason.FORMATNOMAPPING; if ((msg.getApplicationProperties() != null) && (msg.getApplicationProperties().getValue() != null)) { Map<?, ?> msgMap = msg.getApplicationProperties().getValue(); for (Map.Entry<?, ?> entry : msgMap.entrySet()) { if (entry.getKey() instanceof String) {
public static Symbol getResponseErrorCondition(Message responseMessage) { Symbol errorCondition = (Symbol)responseMessage.getApplicationProperties().getValue().get(ClientConstants.REQUEST_RESPONSE_ERROR_CONDITION); if(errorCondition == null) { errorCondition = (Symbol)responseMessage.getApplicationProperties().getValue().get(ClientConstants.REQUEST_RESPONSE_LEGACY_ERROR_CONDITION); } return errorCondition; }
private void lazyCreateApplicationProperties() { if (applicationPropertiesMap == null) { applicationPropertiesMap = new HashMap<>(); message.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap)); } }
private static List<List<String>> collectRouter(SyncRequestClient client, String entityType, List<String> attributeNames) throws Exception { Map<String, Object> properties = new LinkedHashMap<>(); properties.put("operation", "QUERY"); properties.put("entityType", entityType); Map<String, Object> body = new LinkedHashMap<>(); body.put("attributeNames", attributeNames); Message message = Proton.message(); message.setApplicationProperties(new ApplicationProperties(properties)); message.setBody(new AmqpValue(body)); Message response = client.request(message, 10, TimeUnit.SECONDS); AmqpValue value = (AmqpValue) response.getBody(); Map<?,?> values = (Map<?,?>) value.getValue(); @SuppressWarnings("unchecked") List<List<String>> results = (List<List<String>>) values.get("results"); return results; } }
if( maMap!=null ) ma = new MessageAnnotations(maMap); DeliveryAnnotations da=null; if( daMap!=null ) da = new DeliveryAnnotations(daMap); ApplicationProperties ap=null; if( apMap!=null ) ap = new ApplicationProperties(apMap); Footer footer=null; if( footerMap!=null ) footer = new Footer(footerMap);
private static Message createRequestMessageFromValueBody(String operation, Object valueBody, Duration timeout, String associatedLinkName) { Message requestMessage = Message.Factory.create(); requestMessage.setBody(new AmqpValue(valueBody)); HashMap applicationPropertiesMap = new HashMap(); applicationPropertiesMap.put(ClientConstants.REQUEST_RESPONSE_OPERATION_NAME, operation); applicationPropertiesMap.put(ClientConstants.REQUEST_RESPONSE_TIMEOUT, timeout.toMillis()); if(!StringUtil.isNullOrEmpty(associatedLinkName)) { applicationPropertiesMap.put(ClientConstants.REQUEST_RESPONSE_ASSOCIATED_LINK_NAME, associatedLinkName); } requestMessage.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap)); return requestMessage; }