Java Code Examples for org.springframework.amqp.core.MessageProperties#getHeaders()

The following examples show how to use org.springframework.amqp.core.MessageProperties#getHeaders() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitMqTracingUtils.java    From java-spring-rabbitmq with Apache License 2.0 6 votes vote down vote up
static Scope buildSendSpan(Tracer tracer, MessageProperties messageProperties) {
  Tracer.SpanBuilder spanBuilder =
      tracer
          .buildSpan(RabbitMqTracingTags.SPAN_KIND_PRODUCER)
          .ignoreActiveSpan()
          .withTag(Tags.SPAN_KIND.getKey(), RabbitMqTracingTags.SPAN_KIND_PRODUCER);

  ScopeManager scopeManager = tracer.scopeManager();
  Optional<SpanContext> existingSpanContext = Optional.ofNullable(scopeManager)
      .map(ScopeManager::activeSpan)
      .map(Span::context);

  existingSpanContext.ifPresent(spanBuilder::asChildOf);

  if (messageProperties.getHeaders() != null) {
    Optional<SpanContext> messageParentContext = findParent(messageProperties, tracer);
    messageParentContext.ifPresent(spanBuilder::asChildOf);
  }
  Span span = spanBuilder.start();
  return scopeManager.activate(span);
}
 
Example 2
Source File: RabbitMqTracingUtils.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
private static Optional<SpanContext> findParent(
    MessageProperties messageProperties, Tracer tracer) {
  final Map<String, Object> headers = messageProperties.getHeaders();
  SpanContext spanContext =
      tracer.extract(
          Format.Builtin.TEXT_MAP, new RabbitMqMessagePropertiesExtractAdapter(headers));

  if (spanContext == null) {
    return Optional.ofNullable(tracer.activeSpan()).map(Span::context);
  } else {
    return Optional.of(spanContext);
  }
}
 
Example 3
Source File: DmfSenderService.java    From hawkbit-examples with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a action status message.
 *
 * @param actionStatus
 *            the ActionStatus
 * @param actionMessage
 *            the message description
 * @param actionId
 *            the action id
 * @param cacheValue
 *            the cacheValue value
 */
private Message createActionStatusMessage(final String tenant, final DmfActionStatus actionStatus,
        final List<String> updateResultMessages, final Long actionId) {
    final MessageProperties messageProperties = new MessageProperties();
    final Map<String, Object> headers = messageProperties.getHeaders();
    final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(actionId, actionStatus);
    headers.put(MessageHeaderKey.TYPE, MessageType.EVENT.name());
    headers.put(MessageHeaderKey.TENANT, tenant);
    headers.put(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
    headers.put(MessageHeaderKey.CONTENT_TYPE, MessageProperties.CONTENT_TYPE_JSON);
    actionUpdateStatus.addMessage(updateResultMessages);

    return convertMessage(actionUpdateStatus, messageProperties);
}
 
Example 4
Source File: DmfSenderService.java    From hawkbit-examples with Eclipse Public License 1.0 5 votes vote down vote up
private Message createUpdateResultMessage(final SimulatedUpdate cacheValue, final DmfActionStatus actionStatus,
        final List<String> updateResultMessages) {
    final MessageProperties messageProperties = new MessageProperties();
    final Map<String, Object> headers = messageProperties.getHeaders();
    final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(cacheValue.getActionId(),
            actionStatus);
    headers.put(MessageHeaderKey.TYPE, MessageType.EVENT.name());
    headers.put(MessageHeaderKey.TENANT, cacheValue.getTenant());
    headers.put(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
    headers.put(MessageHeaderKey.CONTENT_TYPE, MessageProperties.CONTENT_TYPE_JSON);
    actionUpdateStatus.addMessage(updateResultMessages);
    return convertMessage(actionUpdateStatus, messageProperties);
}
 
Example 5
Source File: DmfReceiverService.java    From hawkbit-examples with Eclipse Public License 1.0 4 votes vote down vote up
private static String getTenant(final Message message) {
    final MessageProperties messageProperties = message.getMessageProperties();
    final Map<String, Object> headers = messageProperties.getHeaders();
    return (String) headers.get(MessageHeaderKey.TENANT);
}