本文整理汇总了Java中org.springframework.messaging.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于org.springframework.messaging包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: zmqOutbound
import org.springframework.messaging.Message; //导入依赖的package包/类
@ServiceActivator(inputChannel = "outbound-zmq", outputChannel = "mark-outboud")
public String zmqOutbound(Message<?> msg) {
try {
ExportString exportString = (ExportString) msg.getPayload();
logger.debug("message arrived at 0MQ outbound sender: " + exportString.getEventId());
// today, for ZMQ, subscribers will listen to pre-subscribed EdgeX
// ZMQ outbound port.
// TODO - someday, reverse the direction and allow clients to set up
// individual ZMQ port to publish out of
logger.debug(".....sending: " + exportString.getEventString());
sendor.sendEventMessage(exportString.getEventString());
// logger.error("--->" + exportString.getEventId() + " [email protected]
// " + System.currentTimeMillis());
logger.info("message sent via 0MQ " + exportString.getEventId());
return exportString.getEventId();
} catch (Exception e) {
logger.error("Problem with sending message via 0MQ: " + e.getMessage());
}
return null;
}
示例2: mqttOutbound
import org.springframework.messaging.Message; //导入依赖的package包/类
@ServiceActivator(inputChannel = "outbound-iotcore", outputChannel = "mark-outboud")
public String mqttOutbound(Message<?> msg) {
try {
ExportString payload = (ExportString) msg.getPayload();
logger.debug("message arrived at IoT Core MQTT outbound sender: " + payload.getEventId());
Addressable addressable = payload.getRegistration().getAddressable();
if (addressable != null) {
// TODO - cache and reuse clients per clientId
// String clientId = addressable.getPublisher();
if (sender == null) {
sender = new IotCoreMQTTSender(addressable, privateKeyFile, algorithm, 0, 600);
}
boolean ok = sender.sendMessage(payload.getEventString().getBytes());
if (!ok) throw new Exception("error while sending message");
logger.info("message sent to IoT Core MQTT broker: " + payload.getRegistration().getAddressable() + " : " + payload.getEventId());
return payload.getEventId();
} else {
logger.error("No MQTT address information provided with registration. Event message not sent for client.");
}
} catch (Exception e) {
logger.error("Problem when sending message via MQTT: " + e.getMessage());
}
return null;
}
示例3: mqttOutbound
import org.springframework.messaging.Message; //导入依赖的package包/类
@ServiceActivator(inputChannel = "outbound-azure", outputChannel = "mark-outboud")
public String mqttOutbound(Message<?> msg) {
try {
ExportString exportString = (ExportString) msg.getPayload();
logger.debug("message arrived at Azure MQTT outbound sender: " + exportString.getEventId());
Addressable addressable = exportString.getRegistration().getAddressable();
if (addressable != null) {
// TODO - someday cache and reuse clients
AzureMQTTSender sender = new AzureMQTTSender(exportString.getRegistration().getAddressable(),
exportString.getDeviceId());
sender.sendMessage(exportString.getEventString().getBytes());
logger.info("message sent to Azure MQTT broker: " + exportString.getRegistration().getAddressable()
+ " : " + exportString.getEventId());
return exportString.getEventId();
} else
logger.error(
"No MQTT address information provided with registration. Event message not sent for client.");
} catch (Exception e) {
logger.error("Problem with sending message via MQTT: " + e.getMessage());
}
return null;
}
示例4: main
import org.springframework.messaging.Message; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void main (String[] args){
ConfigurableApplicationContext ac =
new ClassPathXmlApplicationContext("/context.xml");
PollableChannel feedChannel = ac.getBean("feedChannel", PollableChannel.class);
for (int i = 0; i < 10; i++) {
Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
if (message != null){
System.out.println("==========="+i+"===========");
SyndEntry entry = message.getPayload();
System.out.println(entry.getAuthor());
System.out.println(entry.getPublishedDate());
System.out.println(entry.getTitle());
System.out.println(entry.getUri());
System.out.println(entry.getLink());
System.out.println("======================");
}
}
ac.close();
}
示例5: splitMessage
import org.springframework.messaging.Message; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
@Splitter(inputChannel = "valid-inbound-events", outputChannel = "inbound-eventmessages")
public Object splitMessage(Message<?> msg) {
try {
Message<Event> eventMsg = (Message<Event>) msg;
Event event = eventMsg.getPayload();
logger.debug("message arrived at client message splitter: " + event.getId());
List<ExportRegistration> clients = getClients();
Object o = clients.stream().map(c -> createExportMessage(c, event)).collect(Collectors.toList());
logger.debug("message leaving client message splitter: " + event.getId());
return o;
} catch (Exception e) {
logger.error("problem splitting messages per client request: " + e.getMessage());
throw e;
}
}
示例6: getMqttQualityOfServiceHeaderValue
import org.springframework.messaging.Message; //导入依赖的package包/类
/**
* Retrieves the {@link #QOS} value from the {@code message} parameter.
* <p>
* If the {@code message} parameter is null, doesn't contain the {@link #QOS} header or the
* value cannot be converted to an Integer, the {@code defaultLevelIdentifier} value is
* returned.
*
* @param message a {@link Message} value
* @param defaultLevelIdentifier a default {@link MqttQualityOfService} value if value wasn't
* found or couldn't be parsed
* @return a {@link MqttQualityOfService} value
*/
public static MqttQualityOfService getMqttQualityOfServiceHeaderValue(Message<?> message,
int defaultLevelIdentifier)
{
Integer levelIdentifier = defaultLevelIdentifier;
try
{
if (message != null
&& message.getHeaders().containsKey(QOS))
{
levelIdentifier = message.getHeaders().get(QOS, Integer.class);
}
}
catch (IllegalArgumentException ex)
{
LOG.debug("Could not convert the QOS header value to an Integer!", ex);
}
return MqttQualityOfService.findByLevelIdentifier(levelIdentifier);
}
示例7: when_sending_a_message_containing_tenant_field_should_set_tenant_in_context
import org.springframework.messaging.Message; //导入依赖的package包/类
@Test
public void when_sending_a_message_containing_tenant_field_should_set_tenant_in_context() {
String tenantExpected = "client_id";
ConfigurableApplicationContext context = SpringApplication.run(ApplicationStreamTest.class, "--spring.config.location=classpath:/stream/stream-configuration.properties", "--server.port=0");
Channel channel = context.getBean(Channel.class);
//@formatter:off
Message<?> message = MessageBuilder
.withPayload("{\"message\":\"any message\",\"tenant\":\"client_id\"}")
.setHeader("contentType", "application/json")
.build();
//@formatter:on
channel.queue().send(message);
String tenant = CurrentTenant.get();
Assert.assertEquals("failure of the tenant recovery process", tenantExpected, tenant);
}
示例8: splitMessage
import org.springframework.messaging.Message; //导入依赖的package包/类
@Override
@Splitter(inputChannel = "device-filtered-eventmessages", outputChannel = "reading-filtered-eventmessages")
public Object splitMessage(Message<?> msg) {
try {
ExportMessage exportMsg = (ExportMessage) msg.getPayload();
logger.debug("message arrived at value description filter/splitter: " + exportMsg.getEvent().getId());
ExportFilter filter = exportMsg.getRegistration().getFilter();
if (filter != null && filter.getValueDescriptorIdentifiers() != null
&& (!filter.getValueDescriptorIdentifiers().isEmpty())) {
return filterReadings(exportMsg, filter.getValueDescriptorIdentifiers());
}
logger.debug("message leaving value description filter/splitter: " + exportMsg.getEvent().getId());
return exportMsg;
} catch (Exception e) {
logger.error("problem removing non-relevant readings based on value descriptor: " + e.getMessage());
throw e;
}
}
示例9: when_sending_message_that_does_not_contain_tenant_should_throw_exception_while_trying_to_retrieve
import org.springframework.messaging.Message; //导入依赖的package包/类
@Test
public void when_sending_message_that_does_not_contain_tenant_should_throw_exception_while_trying_to_retrieve() {
expectedException.expect(TenantNotFoundException.class);
expectedException.expectMessage("Tenant not found");
String tenantExpected = null;
ConfigurableApplicationContext context = SpringApplication.run(ApplicationStreamTest.class, "--spring.config.location=classpath:/stream/stream-configuration.properties", "--server.port=0");
Channel channel = context.getBean(Channel.class);
//@formatter:off
Message<?> message = MessageBuilder
.withPayload("{\"message\":\"any message\"}")
.setHeader("contentType", "application/json")
.build();
//@formatter:on
channel.queue().send(message);
String tenant = CurrentTenant.get();
Assert.assertEquals("should throw an exception when it can not recover the tenant", tenantExpected, tenant);
}
示例10: transform
import org.springframework.messaging.Message; //导入依赖的package包/类
@Transformer(inputChannel = "outbound-eventstring", outputChannel = "outbound-compressed-eventstring")
public ExportString transform(Message<?> msg) throws Exception {
try {
ExportString exportString = (ExportString) msg.getPayload();
logger.debug("message arrived at compression transformer: " + exportString.getEventId());
ExportCompression compression = exportString.getRegistration().getCompression();
if (compression != null)
switch (compression) {
case GZIP:
exportString.setEventString(gzipCompression(exportString.getEventString()));
break;
case ZIP:
exportString.setEventString(zipCompression(exportString.getEventString()));
break;
case NONE:
break;
}
logger.debug("message leaving compression transformer " + exportString.getEventId());
return exportString;
} catch (Exception e) {
logger.error("Problem with compression transformation: " + e.getMessage());
throw e;
}
}
示例11: transformJSON
import org.springframework.messaging.Message; //导入依赖的package包/类
@Transformer(inputChannel = "json-inbound-eventmessages", outputChannel = "outbound-eventstring")
public ExportString transformJSON(Message<?> msg) {
try {
ExportMessage exportMsg = (ExportMessage) msg.getPayload();
String eventId = exportMsg.getEvent().getId();
logger.debug("message arrived at JSON format transformer: " + eventId);
ExportString export = new ExportString();
export.setRegistration(exportMsg.getRegistration(), eventId);
export.setEventString(eventToJSON(exportMsg.getEvent()));
logger.debug("message leaving JSON format transformer " + eventId);
return export;
} catch (Exception e) {
logger.error("Problem with JSON format transformation: " + e.getMessage());
throw e;
}
}
示例12: transformIotCoreJSON
import org.springframework.messaging.Message; //导入依赖的package包/类
@Transformer(inputChannel = "iotcore-json-inbound-eventmessages", outputChannel = "outbound-eventstring")
public ExportString transformIotCoreJSON(Message<?> msg) {
try {
ExportMessage exportMsg = (ExportMessage) msg.getPayload();
String eventId = exportMsg.getEvent().getId();
logger.debug("message arrived at IoT Core JSON format transformer: " + eventId);
ExportString export = new ExportString();
export.setRegistration(exportMsg.getRegistration(), eventId);
export.setEventString(eventToJSON(exportMsg.getEvent()));
logger.debug("message leaving IoT Core JSON format transformer " + eventId);
return export;
} catch (Exception e) {
logger.error("Problem with IoT Core JSON format transformation: " + e.getMessage());
throw e;
}
}
示例13: transformAzureJSON
import org.springframework.messaging.Message; //导入依赖的package包/类
@Transformer(inputChannel = "azure-json-inbound-eventmessages", outputChannel = "outbound-eventstring")
public ExportString transformAzureJSON(Message<?> msg) {
try {
ExportMessage exportMsg = (ExportMessage) msg.getPayload();
String eventId = exportMsg.getEvent().getId();
logger.debug("message arrived at Azure JSON format transformer: " + eventId);
ExportString export = new ExportString();
export.setRegistration(exportMsg.getRegistration(), eventId);
export.setEventString(eventToAzureJSON(exportMsg.getEvent()));
export.setDeviceId(exportMsg.getEvent().getDevice());
logger.debug("message leaving Azure JSON format transformer " + eventId);
return export;
} catch (Exception e) {
logger.error("Problem with Azure JSON format transformation: " + e.getMessage());
throw e;
}
}
示例14: transform
import org.springframework.messaging.Message; //导入依赖的package包/类
@Transformer(inputChannel = "serial-inbound-eventmessages", outputChannel = "outbound-eventstring")
public ExportString transform(Message<?> msg) throws Exception {
try {
ExportMessage exportMsg = (ExportMessage) msg.getPayload();
String eventId = exportMsg.getEvent().getId();
logger.debug("message arrived at serialized format transformer: " + eventId);
ExportString export = new ExportString();
export.setRegistration(exportMsg.getRegistration(), eventId);
export.setEventString(toString(exportMsg.getEvent()));
logger.debug("message leaving Serialized format transformer " + eventId);
return export;
} catch (Exception e) {
logger.error("Problem with Serialized format transformation: " + e.getMessage());
throw e;
}
}
示例15: handle
import org.springframework.messaging.Message; //导入依赖的package包/类
@StreamListener(value = Sink.INPUT)
public void handle(Message<ProjectEvent> message) {
ProjectEvent projectEvent = message.getPayload();
log.info("Received new event: " + "{ projectId " + projectEvent.getProjectId() + " -> " +
projectEvent.getType() + " }");
if (projectEvent.getType() == ProjectEventType.CREATED_EVENT) {
try {
commitProcessor.importCommits(projectEvent);
} catch (IOException e) {
throw new RuntimeException("Could not import GitHub project", e);
}
}
if (projectEvent.getType() == ProjectEventType.COMMIT_EVENT) {
// Update query models
LambdaResponse<Map<String, Object>> response =
projectQueries.getTightCoupling().apply(projectEvent);
}
}