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


Java MessageBuilder.withPayload方法代码示例

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


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

示例1: testMqttQualityOfServiceHeader

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Test
public void testMqttQualityOfServiceHeader()
{
    Assert.assertEquals(MqttQualityOfService.QOS_2,
        MqttHeaderHelper.getMqttQualityOfServiceHeaderValue(null,
            MqttQualityOfService.QOS_2.getLevelIdentifier()));
    MessageBuilder<String> builder = MessageBuilder.withPayload("See QoS header");
    Assert.assertEquals(MqttQualityOfService.QOS_2,
        MqttHeaderHelper.getMqttQualityOfServiceHeaderValue(builder.build(),
            MqttQualityOfService.QOS_2.getLevelIdentifier()));
    builder.setHeader(MqttHeaderHelper.QOS, "blah!");
    Assert.assertEquals(MqttQualityOfService.QOS_2,
        MqttHeaderHelper.getMqttQualityOfServiceHeaderValue(builder.build(),
            MqttQualityOfService.QOS_2.getLevelIdentifier()));
    builder.setHeader(MqttHeaderHelper.QOS, MqttQualityOfService.QOS_1.getLevelIdentifier());
    Assert.assertEquals(MqttQualityOfService.QOS_1,
        MqttHeaderHelper.getMqttQualityOfServiceHeaderValue(builder.build(),
            MqttQualityOfService.QOS_2.getLevelIdentifier()));
}
 
开发者ID:christophersmith,项目名称:summer-mqtt,代码行数:20,代码来源:MqttHeaderHelperTest.java

示例2: 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

示例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: testTopicHeader

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Test
public void testTopicHeader()
{
    Assert.assertNull(MqttHeaderHelper.getTopicHeaderValue(null));
    MessageBuilder<String> builder = MessageBuilder.withPayload("See topic header");
    Assert.assertNull(MqttHeaderHelper.getTopicHeaderValue(builder.build()));
    builder.setHeader(MqttHeaderHelper.TOPIC, TOPIC);
    Assert.assertEquals(TOPIC, MqttHeaderHelper.getTopicHeaderValue(builder.build()));
}
 
开发者ID:christophersmith,项目名称:summer-mqtt,代码行数:10,代码来源:MqttHeaderHelperTest.java

示例5: testRetainedHeader

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Test
public void testRetainedHeader()
{
    Assert.assertFalse(MqttHeaderHelper.getRetainedHeaderValue(null));
    MessageBuilder<String> builder = MessageBuilder.withPayload("See retained header");
    Assert.assertFalse(MqttHeaderHelper.getRetainedHeaderValue(builder.build()));
    builder.setHeader(MqttHeaderHelper.RETAINED, "foo");
    Assert.assertFalse(MqttHeaderHelper.getRetainedHeaderValue(builder.build()));
    builder.setHeader(MqttHeaderHelper.RETAINED, true);
    Assert.assertTrue(MqttHeaderHelper.getRetainedHeaderValue(builder.build()));
}
 
开发者ID:christophersmith,项目名称:summer-mqtt,代码行数:12,代码来源:MqttHeaderHelperTest.java

示例6: testCorrelationIdHeader

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Test
public void testCorrelationIdHeader()
{
    Assert.assertNull(MqttHeaderHelper.getCorrelationIdHeaderValue(null));
    MessageBuilder<String> builder = MessageBuilder.withPayload("See Correlation ID header");
    Assert.assertNull(MqttHeaderHelper.getCorrelationIdHeaderValue(builder.build()));
    builder.setHeader(MqttHeaderHelper.CORRELATION_ID, "foo");
    Assert.assertSame("foo", MqttHeaderHelper.getCorrelationIdHeaderValue(builder.build()));
}
 
开发者ID:christophersmith,项目名称:summer-mqtt,代码行数:10,代码来源:MqttHeaderHelperTest.java

示例7: resolveArgument

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
    Payload ann = parameter.getParameterAnnotation(Payload.class);
    if (ann != null && StringUtils.hasText(ann.value())) {
        throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver");
    }

    Object payload = message.getPayload();
    boolean isGeneric = isGenericMessage(payload);
    if (isGeneric) {
        payload = ((GenericMessage) payload).getContent();
        MessageBuilder<Object> builder = MessageBuilder.withPayload(payload);
        message = builder.copyHeadersIfAbsent(message.getHeaders()).build();
    }
    if (isEmptyPayload(payload)) {
        if (ann == null || ann.required()) {
            bindEmptyPayloadError(parameter, message, payload);
        }
        return null;
    }

    if (isGeneric) {
        return convertFromMessage(parameter, message);
    } else {
        if (ClassUtils.isAssignable(parameter.getParameterType(), payload.getClass())) {
            validate(message, parameter, payload);
            return payload;
        }
        return convertFromMessage(parameter, message);
    }
}
 
开发者ID:kinglcc,项目名称:spring-boot-jms,代码行数:32,代码来源:Jackson2PayloadArgumentResolver.java

示例8: 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

示例9: 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

示例10: fromMessage

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object fromMessage(javax.jms.Message message) throws JMSException, MessageConversionException {
	if (message == null) {
		return null;
	}
	Map<String, Object> mappedHeaders = this.headerMapper.toHeaders(message);
	Object convertedObject = extractPayload(message);
	MessageBuilder<Object> builder = (convertedObject instanceof org.springframework.messaging.Message) ?
			MessageBuilder.fromMessage((org.springframework.messaging.Message<Object>) convertedObject) :
			MessageBuilder.withPayload(convertedObject);
	return builder.copyHeadersIfAbsent(mappedHeaders).build();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:MessagingMessageConverter.java

示例11: initBuilder

import org.springframework.messaging.support.MessageBuilder; //导入方法依赖的package包/类
private MessageBuilder<String> initBuilder() {
	return MessageBuilder.withPayload("test");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:4,代码来源:SimpleJmsHeaderMapperTests.java

示例12: 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.withPayload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。