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


Java Message类代码示例

本文整理汇总了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;
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:21,代码来源:ZMQOutboundServiceActivator.java

示例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;
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:26,代码来源:IotCoreMQTTOutboundServiceActivator.java

示例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;
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:23,代码来源:AzureMQTTOutboundServiceActivator.java

示例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();


}
 
开发者ID:paulossjunior,项目名称:spring_integration_examples,代码行数:26,代码来源:Application.java

示例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;
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:18,代码来源:ClientMessageSplitter.java

示例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);
}
 
开发者ID:christophersmith,项目名称:summer-mqtt,代码行数:31,代码来源:MqttHeaderHelper.java

示例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);
}
 
开发者ID:wesley-ramos,项目名称:spring-multitenancy,代码行数:20,代码来源:StreamTest.java

示例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;
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:19,代码来源:ValueDescriptorSplitter.java

示例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);
}
 
开发者ID:wesley-ramos,项目名称:spring-multitenancy,代码行数:23,代码来源:StreamTest.java

示例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;
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:25,代码来源:CompressionTransformer.java

示例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;
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:17,代码来源:JSONFormatTransformer.java

示例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;
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:17,代码来源:JSONFormatTransformer.java

示例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;
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:18,代码来源:JSONFormatTransformer.java

示例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;
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:17,代码来源:SerializedFormatTransformer.java

示例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);
    }
}
 
开发者ID:kbastani,项目名称:service-block-samples,代码行数:21,代码来源:EventProcessor.java


注:本文中的org.springframework.messaging.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。