本文整理汇总了Java中org.springframework.amqp.core.MessageProperties.setCorrelationId方法的典型用法代码示例。如果您正苦于以下问题:Java MessageProperties.setCorrelationId方法的具体用法?Java MessageProperties.setCorrelationId怎么用?Java MessageProperties.setCorrelationId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.amqp.core.MessageProperties
的用法示例。
在下文中一共展示了MessageProperties.setCorrelationId方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: packAndSend
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
/**
* Convert a message to the appropriate Message class and send it using a response correlationId.
*
* @param receiver
* the receiver of the message.
* @param baseMessage
* the message to be send.
* @param responseTo
* correlationId where the message is a response to.
* @return outcome of the send method. An valid UUID if the message was send correctly, null if it was not.
*/
public String packAndSend(String receiver, BaseMessage baseMessage, String responseTo)
{
MessageProperties properties = new MessageProperties();
String uuid = responseTo == null || responseTo == "" ? UUID.randomUUID().toString() : responseTo;
properties.setCorrelationId(uuid.getBytes());
properties.setTimestamp(new Date());
byte[] messageBytes = MessageSerializer.serialize(baseMessage);
Message message = new Message(messageBytes, properties);
if (objSender.sendMessage(receiver, message))
{
return uuid;
}
return null;
}
示例2: testSending
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
/**
* Test the send method for messages.
*
* @throws Exception
* reason of failure given by the test.
*/
@Test
public void testSending() throws Exception
{
System.out.print("SendController : Testing sending a message...");
Resources otherResources = new Resources();
otherResources.getConfiguration().loadConfiguration("/test.properties");
otherResources.getConfiguration().setName("other");
new ReceiveController(otherResources);
MessageProperties props = new MessageProperties();
props.setCorrelationId(this.objController.generateUniqueId().getBytes());
BaseMessage baseMsg = new GenerationMessage();
baseMsg.setPayload("Hello World");
Message msg = new Message(MessageSerializer.serialize(baseMsg), props);
boolean exists = this.objController.sendMessage("other", msg);
assertTrue("The receiver does not exist", exists);
exists = this.objController.sendMessage("none", msg);
assertFalse("The receiver does exist", exists);
System.out.println("done.");
}
示例3: testReceiving
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
/**
* Test the receive method for messages.
*
* @throws Exception
* reason of failure given by the test.
*/
@Test
public void testReceiving() throws Exception
{
System.out.print("ReceiveController : Testing receiving a message...");
Resources otherResources = new Resources();
otherResources.getConfiguration().loadConfiguration("/test.properties");
otherResources.getConfiguration().setName("other");
SendController sender = new SendController(otherResources);
MessageProperties props = new MessageProperties();
props.setCorrelationId(sender.generateUniqueId().getBytes());
BaseMessage baseMsg = new GenerationMessage();
baseMsg.setPayload("Hello World");
Message msg = new Message(MessageSerializer.serialize(baseMsg), props);
boolean exists = sender.sendMessage("test", msg);
assertTrue("The receiver does not exist", exists);
Message receiverdMsg = this.objReceiver.receiveMessage(1000);
//assertNotNull("The received message cannot be null.", receiverdMsg);
System.out.println("done.");
}
示例4: toMessage
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
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);
}
}
示例5: transform
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
/**
* Transforms AV message to AMQP message.
*
* @param msg the AV message
* @return the AMQP message
* @throws MapperException if mapping failed
*/
public Message transform(AvMessage msg) throws MapperException {
log.debug("AVTransform: " + msg);
requireNonNull(msg, "Message must not be null!");
// mandatory fields
if (msg.getId() == null) {
throw new MapperException("Message ID must not be null");
} else if (msg.getType() == null) {
throw new MapperException("Message type must not be null");
}
MessageProperties props = new MessageProperties();
props.setMessageId(msg.getId());
props.setType(msg.getType().toString());
// correlation ID
if (msg.getCorrelationId() != null) {
props.setCorrelationId(msg.getCorrelationId());
}
// virus info
props.setHeader(VIRUS_INFO_KEY, msg.getVirusInfo());
// owner
props.setHeader(OWNER_KEY, msg.getOwner());
// filename
props.setHeader(FILENAME_KEY, msg.getFilename());
return new Message(msg.getData(), props);
}
示例6: ping
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
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.getBytes());
messageProperties.setReplyTo(amqpProperties.getSenderForSpExchange());
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
sendMessage(spExchange, new Message(null, messageProperties));
}
示例7: createEventMessage
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
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.getBytes());
return createMessage(payload, messageProperties);
}
示例8: createPingMessage
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
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.getBytes());
messageProperties.setReplyTo(DmfTestConfiguration.REPLY_TO_EXCHANGE);
return createMessage(null, messageProperties);
}
示例9: postProcessMessage
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Override
public Message postProcessMessage(final Message message) throws AmqpException {
MessageProperties messageProperties = message.getMessageProperties();
messageProperties.setReplyToAddress(responseAddress);
messageProperties.setMessageId(messageId.asString());
messageProperties.setCorrelationId(correlationId.asByteArray());
return message;
}
示例10: testSendMessages
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
/**
* Test the getting, setting and removal of send messages.
*
* @throws Exception
* reason of failure given by the test.
*/
@Test
public void testSendMessages() throws Exception
{
System.out.print("DataContainer : Testing getting, setting and removal of send messages...");
MessageProperties properties = new MessageProperties();
properties.setCorrelationId(new String("1234567890").getBytes());
Message msgOne = new Message("Hello First World".getBytes(), properties);
properties.setCorrelationId(new String("1234567890").getBytes());
Message msgTwo = new Message("Hello Second World".getBytes(), properties);
this.objContainer.addSendMessage(msgOne);
this.objContainer.addSendMessage(msgTwo);
ConcurrentSkipListMap<Integer, Message> sendMessages = new ConcurrentSkipListMap<Integer, Message>();
sendMessages.put(0, msgOne);
sendMessages.put(1, msgTwo);
ConcurrentSkipListMap<Integer, Message> otherMessages = this.objContainer.getSendMessages();
assertNotNull("The set with message cannot be Null.", otherMessages);
assertEquals("The sets with messages where not the same.", otherMessages.size(), sendMessages.size());
this.objContainer.removeSendMessage(msgOne);
assertNotEquals("The sets with messages cannot be the same.", otherMessages.size(), sendMessages.size());
sendMessages.remove(0);
assertEquals("The sets with messages where not the same.", otherMessages.size(), sendMessages.size());
System.out.println("done.");
}
示例11: toReplyMessage
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
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);
}