当前位置: 首页>>代码示例>>Java>>正文


Java MessageBuilder.build方法代码示例

本文整理汇总了Java中org.springframework.messaging.support.MessageBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java MessageBuilder.build方法的具体用法?Java MessageBuilder.build怎么用?Java MessageBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.messaging.support.MessageBuilder的用法示例。


在下文中一共展示了MessageBuilder.build方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: preSend

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
	Span parentSpan = getTracer().isTracing() ? getTracer().getCurrentSpan()
			: buildSpan(message);
	String name = getMessageChannelName(channel);
	Span span = startSpan(parentSpan, name, message);
	MessageBuilder<?> messageBuilder = MessageBuilder.fromMessage(message);
	if (message.getHeaders().containsKey(MESSAGE_SENT_FROM_CLIENT)) {
		span.logEvent(Span.SERVER_RECV);
	} else {
		span.logEvent(Span.CLIENT_SEND);
		messageBuilder.setHeader(MESSAGE_SENT_FROM_CLIENT, true);
	}
	getSpanInjector().inject(span, messageBuilder);
	return messageBuilder.build();
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:17,代码来源:TraceChannelInterceptor.java

示例2: nativeSpanHeadersAdded

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Test
public void nativeSpanHeadersAdded() {
	Span span = Span.builder().name("http:foo").spanId(1L).traceId(2L).build();
	MessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
	Message<String> messageToBuild = MessageBuilder.createMessage("Hello World",
			accessor.getMessageHeaders());
	MessageBuilder<String> messageBuilder = MessageBuilder
			.fromMessage(messageToBuild);

	this.messagingSpanInjector.inject(span, messageBuilder);

	Message<String> message = messageBuilder.build();
	assertThat(message.getHeaders())
			.containsKey(NativeMessageHeaderAccessor.NATIVE_HEADERS);
	MessageHeaderAccessor natives = NativeMessageHeaderAccessor
			.getMutableAccessor(message);
	assertThat(natives.getMessageHeaders()).containsKey(Span.SPAN_ID_NAME);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:19,代码来源:MessagingSpanInjectorTests.java

示例3: poll

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
private Message<Collection<Object>> poll(String channel, String key,
		boolean requeue) {
	List<Object> list = new ArrayList<>();
	List<Message<?>> messages = new ArrayList<>();
	Bridge<Message<?>> queue = queues.get(new Route(key, channel).getPath());
	if (queue != null) {
		queue.receive().subscribe(message -> {
			messages.add(message);
			list.add(message.getPayload());
		});
		if (!requeue) {
			queue.reset();
		}
	}
	MessageBuilder<Collection<Object>> builder = MessageBuilder.withPayload(list);
	if (!messages.isEmpty()) {
		builder.copyHeadersIfAbsent(messages.get(0).getHeaders());
	}
	return builder.build();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-function,代码行数:21,代码来源:MessageController.java

示例4: doConvert

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Override
protected Message<?> doConvert(Object payload, Map<String, Object> headers, MessagePostProcessor postProcessor) {
    String content;
    if (payload instanceof String) {
        content = (String) payload;
    } else {
        // if payload not as string, use objectMapper change it.
        try {
            content = objectMapper.writeValueAsString(payload);
        } catch (JsonProcessingException e) {
            log.info("convert payload to String failed. payload:{}", payload);
            throw new RuntimeException("convert to payload to String failed.", e);
        }
    }

    MessageBuilder<?> builder = MessageBuilder.withPayload(content);
    if (headers != null) {
        builder.copyHeaders(headers);
    }
    builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN);

    Message<?> message = builder.build();
    if (postProcessor != null) {
        message = postProcessor.postProcessMessage(message);
    }
    return message;
}
 
开发者ID:QianmiOpen,项目名称:spring-boot-starter-rocketmq,代码行数:28,代码来源:RocketMQTemplate.java

示例5: preSendClientSpan

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
private Message<?> preSendClientSpan(Message<?> message) {
  Span span = tracer.buildSpan((String) message.getHeaders()
      .getOrDefault(SIMP_DESTINATION, UNKNOWN_DESTINATION))
      .withTag(Tags.SPAN_KIND.getKey(), spanKind)
      .withTag(Tags.COMPONENT.getKey(), WEBSOCKET)
      .startManual();
  MessageBuilder<?> messageBuilder = MessageBuilder.fromMessage(message)
      .setHeader(OPENTRACING_SPAN, span);
  tracer
      .inject(span.context(), Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(messageBuilder));
  return messageBuilder.build();
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:13,代码来源:TracingChannelInterceptor.java

示例6: toMessage

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Override
public final Message<?> toMessage(Object payload, MessageHeaders headers, Object conversionHint) {
	if (!canConvertTo(payload, headers)) {
		return null;
	}

	payload = convertToInternal(payload, headers, conversionHint);
	if (payload == null) {
		return null;
	}

	MimeType mimeType = getDefaultContentType(payload);
	if (headers != null) {
		MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, MessageHeaderAccessor.class);
		if (accessor != null && accessor.isMutable()) {
			accessor.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
			return MessageBuilder.createMessage(payload, accessor.getMessageHeaders());
		}
	}

	MessageBuilder<?> builder = MessageBuilder.withPayload(payload);
	if (headers != null) {
		builder.copyHeaders(headers);
	}
	builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
	return builder.build();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:AbstractMessageConverter.java

示例7: message

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
private Message<byte[]> message(SimpMessageType messageType) {
	MessageBuilder<byte[]> builder = MessageBuilder.withPayload(new byte[0]);
	if (messageType != null) {
		builder.setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, messageType);
	}
	return builder.build();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:SimpMessageTypeMessageConditionTests.java

示例8: inject

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Override
public void inject(Span span, MessageBuilder<?> carrier) {
	Message<?> initialMessage = carrier.build();
	MessageHeaderAccessor accessor = MessageHeaderAccessor
			.getMutableAccessor(initialMessage);
	if (span == null) {
		if (!Span.SPAN_SAMPLED
				.equals(initialMessage.getHeaders().get(Span.SAMPLED_NAME))) {
			accessor.setHeader(Span.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED);
			carrier.setHeaders(accessor);
			return;
		}
		return;
	}
	Map<String, String> headers = new HashMap<>();
	addHeader(headers, Span.TRACE_ID_NAME, Span.idToHex(span.getTraceId()));
	addHeader(headers, Span.SPAN_ID_NAME, Span.idToHex(span.getSpanId()));
	if (span.isExportable()) {
		addAnnotations(this.traceKeys, initialMessage, span);
		Long parentId = getFirst(span.getParents());
		if (parentId != null) {
			addHeader(headers, Span.PARENT_ID_NAME, Span.idToHex(parentId));
		}
		addHeader(headers, Span.SPAN_NAME_NAME, span.getName());
		addHeader(headers, Span.PROCESS_ID_NAME, span.getProcessId());
		addHeader(headers, Span.SAMPLED_NAME, Span.SPAN_SAMPLED);
	}
	else {
		addHeader(headers, Span.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED);
	}
	accessor.setHeader(SPAN_HEADER, span);
	accessor.copyHeaders(headers);
	if (accessor instanceof NativeMessageHeaderAccessor) {
		NativeMessageHeaderAccessor nativeAccessor = (NativeMessageHeaderAccessor) accessor;
		for (String name : headers.keySet()) {
			nativeAccessor.setNativeHeader(name, headers.get(name));
		}
	}
	carrier.setHeaders(accessor);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:41,代码来源:MessagingSpanInjector.java

示例9: forPayload

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
private static Message<?> forPayload(String metricName, Object payload) {
	MessageBuilder<Object> builder = MessageBuilder.withPayload(payload);
	builder.setHeader(METRIC_NAME, metricName);
	return builder.build();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:6,代码来源:MetricMessage.java


注:本文中的org.springframework.messaging.support.MessageBuilder.build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。