本文整理汇总了Java中org.springframework.amqp.core.MessageProperties.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java MessageProperties.setContentType方法的具体用法?Java MessageProperties.setContentType怎么用?Java MessageProperties.setContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.amqp.core.MessageProperties
的用法示例。
在下文中一共展示了MessageProperties.setContentType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkContentTypeJson
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
/**
* Method to validate if content type is set in the message properties.
*
* @param message
* the message to get validated
*/
private void checkContentTypeJson(final Message message) {
if (message.getBody().length == 0) {
return;
}
final MessageProperties messageProperties = message.getMessageProperties();
final String headerContentType = (String) messageProperties.getHeaders().get("content-type");
if (null != headerContentType) {
messageProperties.setContentType(headerContentType);
}
final String contentType = messageProperties.getContentType();
if (contentType != null && contentType.contains("json")) {
return;
}
throw new AmqpRejectAndDontRequeueException("Content-Type is not JSON compatible");
}
示例2: processMessageProperties
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
private void processMessageProperties(MessageProperties messageProperties) {
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
messageProperties.setContentEncoding("UTF-8");
messageProperties.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
messageProperties.setHeader(MessageHeaders.HOST, OSUtils.getHostName());
messageProperties.setAppId(AppInfo.getApplicationName());
if(this.messagePropertiesCallback != null) {
this.messagePropertiesCallback.call(messageProperties);
}
}
示例3: send
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
public void send(Document document){
MessageProperties messageProperties = new MessageProperties();
messageProperties.setContentType("text/xml");
byte[] body = XmlUtils.toXML(document).getBytes();
Message message = new Message(body, messageProperties);
rabbitTemplate.send(message);
}
示例4: 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));
}
示例5: thingCreatedMessage
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
private Message thingCreatedMessage(final String tenant, final String targetId) {
final MessageProperties messagePropertiesForSP = new MessageProperties();
messagePropertiesForSP.setHeader(MessageHeaderKey.TYPE, MessageType.THING_CREATED.name());
messagePropertiesForSP.setHeader(MessageHeaderKey.TENANT, tenant);
messagePropertiesForSP.setHeader(MessageHeaderKey.THING_ID, targetId);
messagePropertiesForSP.setHeader(MessageHeaderKey.SENDER, "simulator");
messagePropertiesForSP.setContentType(MessageProperties.CONTENT_TYPE_JSON);
messagePropertiesForSP.setReplyTo(amqpProperties.getSenderForSpExchange());
return new Message(null, messagePropertiesForSP);
}
示例6: attributeUpdateMessage
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
private Message attributeUpdateMessage(final String tenant, final String targetId) {
final MessageProperties messagePropertiesForSP = new MessageProperties();
messagePropertiesForSP.setHeader(MessageHeaderKey.TYPE, MessageType.EVENT.name());
messagePropertiesForSP.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ATTRIBUTES);
messagePropertiesForSP.setHeader(MessageHeaderKey.TENANT, tenant);
messagePropertiesForSP.setHeader(MessageHeaderKey.THING_ID, targetId);
messagePropertiesForSP.setContentType(MessageProperties.CONTENT_TYPE_JSON);
messagePropertiesForSP.setReplyTo(amqpProperties.getSenderForSpExchange());
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
attributeUpdate.getAttributes().putAll(simulationProperties.getAttributes().stream().collect(
Collectors.toMap(SimulationProperties.Attribute::getKey, SimulationProperties.Attribute::getValue)));
return convertMessage(attributeUpdate, messagePropertiesForSP);
}
示例7: createConnectorMessageProperties
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
private static MessageProperties createConnectorMessageProperties(final String tenant, final String controllerId) {
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
messageProperties.setHeader(MessageHeaderKey.CONTENT_TYPE, MessageProperties.CONTENT_TYPE_JSON);
messageProperties.setHeader(MessageHeaderKey.THING_ID, controllerId);
messageProperties.setHeader(MessageHeaderKey.TENANT, tenant);
return messageProperties;
}
示例8: wrongContentType
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Test
@Description("Tests not allowed content-type in message")
public void wrongContentType() {
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setContentType("xml");
final Message message = new Message(new byte[0], messageProperties);
try {
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, "vHost");
fail("AmqpRejectAndDontRequeueException was excepeted due to worng content type");
} catch (final AmqpRejectAndDontRequeueException e) {
}
}
示例9: createMessageProperties
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
private MessageProperties createMessageProperties(final MessageType type, final String replyTo) {
final MessageProperties messageProperties = new MessageProperties();
if (type != null) {
messageProperties.setHeader(MessageHeaderKey.TYPE, type.name());
}
messageProperties.setHeader(MessageHeaderKey.TENANT, TENANT);
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
messageProperties.setReplyTo(replyTo);
return messageProperties;
}
示例10: createMessage
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
protected Message createMessage(final Object payload, final MessageProperties messageProperties) {
if (payload == null) {
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
return new Message(null, messageProperties);
}
return getDmfClient().getMessageConverter().toMessage(payload, messageProperties);
}
示例11: handle
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
@Override
public void handle(ConsentSignedEvent event) {
MessageProperties messageProperties = new MessageProperties();
messageProperties.setHeader("messageType", event.getClass().getName());
messageProperties.setContentType("text/plain");
messageSender.send(event.getConsentId().toString(), messageProperties);
}
示例12: createJsonProperties
import org.springframework.amqp.core.MessageProperties; //导入方法依赖的package包/类
private MessageProperties createJsonProperties() {
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
return messageProperties;
}