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

The following examples show how to use org.springframework.amqp.core.MessageProperties#setCorrelationId() . 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: AbstractMqMessageConverter.java    From zxl with Apache License 2.0 6 votes vote down vote up
protected <T> Message toMessage(T object, String correlationId, boolean isOnlySend) {
	if (object == null) {
		return null;
	}
	if (object instanceof Message) {
		return (Message) object;
	}
	MessageProperties messageProperties = new MessageProperties();
	messageProperties.setMessageId(UUID.randomUUID().toString());
	messageProperties.setContentEncoding(DEFAULT_CHARSET);
	try {
		if (!isOnlySend) {
			if (correlationId == null) {
				messageProperties.setCorrelationId(UUID.randomUUID().toString().getBytes(DEFAULT_CHARSET));
			} else {
				messageProperties.setCorrelationId(correlationId.getBytes(DEFAULT_CHARSET));
			}
		}
		byte[] bytes = getBytesAndSetMessageProperties(object, messageProperties);
		return new Message(bytes, messageProperties);
	} catch (Exception warnException) {
		throw new RuntimeException("#####��Ϣת��ʧ��", warnException);
	}
}
 
Example 2
Source File: DmfSenderService.java    From hawkbit-examples with Eclipse Public License 1.0 5 votes vote down vote up
public void ping(final String tenant, final String correlationId) {
    final MessageProperties messageProperties = new MessageProperties();
    messageProperties.getHeaders().put(MessageHeaderKey.TENANT, tenant);
    messageProperties.getHeaders().put(MessageHeaderKey.TYPE, MessageType.PING.toString());
    messageProperties.setCorrelationId(correlationId);
    messageProperties.setReplyTo(amqpProperties.getSenderForSpExchange());
    messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);

    sendMessage(spExchange, new Message(null, messageProperties));
}
 
Example 3
Source File: AmqpMessageHandlerServiceIntegrationTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private Message createEventMessage(final String tenant, final EventTopic eventTopic, final Object payload) {
    final MessageProperties messageProperties = createMessagePropertiesWithTenant(tenant);
    messageProperties.getHeaders().put(MessageHeaderKey.TYPE, MessageType.EVENT.toString());
    messageProperties.getHeaders().put(MessageHeaderKey.TOPIC, eventTopic.toString());
    messageProperties.setCorrelationId(CORRELATION_ID);

    return createMessage(payload, messageProperties);
}
 
Example 4
Source File: AbstractAmqpServiceIntegrationTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
protected Message createPingMessage(final String correlationId, final String tenant) {
    final MessageProperties messageProperties = createMessagePropertiesWithTenant(tenant);
    messageProperties.getHeaders().put(MessageHeaderKey.TYPE, MessageType.PING.toString());
    messageProperties.setCorrelationId(correlationId);
    messageProperties.setReplyTo(DmfTestConfiguration.REPLY_TO_EXCHANGE);

    return createMessage(null, messageProperties);
}
 
Example 5
Source File: SpringMessageConverterAdapter.java    From zxl with Apache License 2.0 5 votes vote down vote up
public <T> Message toReplyMessage(T object, String correlationId) {
	MessageProperties messageProperties = new MessageProperties();
	try {
		messageProperties.setCorrelationId(correlationId.getBytes(DEFAULT_CHARSET));
	} catch (UnsupportedEncodingException e) {}
	return messageConverter.toMessage(object, messageProperties);
}