本文整理汇总了Java中org.springframework.integration.support.MessageBuilder类的典型用法代码示例。如果您正苦于以下问题:Java MessageBuilder类的具体用法?Java MessageBuilder怎么用?Java MessageBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageBuilder类属于org.springframework.integration.support包,在下文中一共展示了MessageBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restOutbound
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@ServiceActivator(inputChannel = "outbound-rest", outputChannel = "mark-outboud")
public String restOutbound(Message<?> msg) {
try {
ExportString exportString = (ExportString) msg.getPayload();
logger.debug("message arrived at REST outbound sender: " + exportString.getEventId());
Addressable addressable = exportString.getRegistration().getAddressable();
String uri = addressable.getAddress() + ":" + addressable.getPort() + addressable.getPath();
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(uri);
handler.setHttpMethod(HttpMethod.POST);
handler.setExpectReply(false);
Message<String> message = MessageBuilder.withPayload(exportString.getEventString()).build();
handler.handleMessage(message);
logger.info("message sent to REST address: " + uri + " : " + exportString.getEventId());
return exportString.getEventId();
} catch (Exception e) {
logger.error("Problem with sending message via REST: " + e.getMessage());
return null;
}
}
示例2: testSendBinaryDataWithContentType
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Test
public void testSendBinaryDataWithContentType() throws Exception {
try (ConfigurableApplicationContext context = SpringApplication.run(
SourceApplication.class, "--server.port=0",
"--spring.jmx.enabled=false",
"--spring.cloud.stream.bindings.output.contentType=image/jpeg")) {
MessageCollector collector = context.getBean(MessageCollector.class);
Source source = context.getBean(Source.class);
byte[] data = new byte[] { 0, 1, 2, 3 };
source.output().send(MessageBuilder.withPayload(data)
.build());
Message<byte[]> message = (Message<byte[]>) collector
.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
.includes(MimeTypeUtils.IMAGE_JPEG));
assertThat(message.getPayload()).isEqualTo(data);
}
}
示例3: setup
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Before
public void setup() {
activator = new IotCoreMQTTOutboundServiceActivator();
string = ExportStringData.newTestInstance();
string.setEventString(TEST_STRING);
string.setEventId(TEST_ID);
Addressable addressable = new Addressable(TEST_STRING, Protocol.OTHER, TEST_ADDRESS, TEST_PORT, TEST_PUBLISHER,
TEST_USER, TEST_PASSWORD, TEST_TOPIC);
ExportRegistration er = new ExportRegistration();
er.setAddressable(addressable);
string.setRegistration(er, TEST_ID);
message = MessageBuilder.withPayload(string).build();
try {
FieldUtils.writeField(activator, "privateKeyFile", "rsa_private_pkcs8", true);
FieldUtils.writeField(activator, "algorithm", "RS256", true);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
示例4: testEvaluationPositive
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Test
public void testEvaluationPositive() throws IOException {
try(InputStream is = new ClassPathResource("/images/panda.jpeg").getInputStream()) {
byte[] image = IOUtils.toByteArray(is);
channels.input().send(MessageBuilder.withPayload(image).build());
Message<String> received = (Message<String>) messageCollector.forChannel(channels.output()).poll();
Assert.assertTrue(received.getPayload().getClass().isAssignableFrom(String.class));
Assert.assertThat(received.getPayload().toString(),
equalTo("{\"alternatives\":[" +
"{\"giant panda\":0.98649305}," +
"{\"badger\":0.010562794}," +
"{\"ice bear\":0.001130851}]," +
"\"label\":\"giant panda\"}"));
}
}
开发者ID:tzolov,项目名称:tensorflow-spring-cloud-stream-app-starters,代码行数:21,代码来源:LabelImageTensorflowProcessorIntegrationTests.java
示例5: produceBookingOrderEvent
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
/**
*
* @param booking
* @throws Exception
*/
@Override
public void produceBookingOrderEvent(Booking booking) throws Exception {
final BookingOrder.Builder boBuilder = BookingOrder.newBuilder();
boBuilder.setId(booking.getId());
boBuilder.setName(booking.getName());
boBuilder.setRestaurantId(booking.getRestaurantId());
boBuilder.setTableId(booking.getTableId());
boBuilder.setUserId(booking.getUserId());
boBuilder.setDate(booking.getDate().toString());
boBuilder.setTime(booking.getTime().toString());
BookingOrder bo = boBuilder.build();
final Message<BookingOrder> message = MessageBuilder.withPayload(bo).build();
bookingMessageChannels.bookingOrderOutput().send(message);
LOG.info("sending bookingOrder: {}", booking);
}
开发者ID:PacktPublishing,项目名称:Mastering-Microservices-with-Java-9-Second-Edition,代码行数:21,代码来源:BookingServiceImpl.java
示例6: when_sending_message_that_does_not_contain_tenant_should_throw_exception_while_trying_to_retrieve
import org.springframework.integration.support.MessageBuilder; //导入依赖的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);
}
示例7: when_sending_a_message_containing_tenant_field_should_set_tenant_in_context
import org.springframework.integration.support.MessageBuilder; //导入依赖的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: when_sending_a_json_containing_tenat_field_must_return_the_value
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Test
public void when_sending_a_json_containing_tenat_field_must_return_the_value() {
String tenantExpected = "client_id";
TenantConfigLoader tenantConfigLoader = new TenantConfigLoader();
tenantConfigLoader.setField("tenant");
Mockito.when(multitenancyConfigLoader.getTenant()).thenReturn(tenantConfigLoader);
//@formatter:off
Message<?> message = MessageBuilder
.withPayload("{\"id\":1,\"name\":\"wesley\",\"tenant\":\"client_id\"}")
.setHeader("contentType","application/json")
.build();
//@formatter:on
TenantStrategyJson tenantStrategyJson = new TenantStrategyJson(multitenancyConfigLoader);
String tenant = tenantStrategyJson.getValue(message);
Assert.assertEquals(tenantExpected, tenant);
}
示例9: when_to_send_a_json_that_does_not_contain_the_tenant_field_should_return_null
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Test
public void when_to_send_a_json_that_does_not_contain_the_tenant_field_should_return_null() {
String tenantExpected = null;
TenantConfigLoader tenantConfigLoader = new TenantConfigLoader();
tenantConfigLoader.setField("tenant");
Mockito.when(multitenancyConfigLoader.getTenant()).thenReturn(tenantConfigLoader);
//@formatter:off
Message<?> message = MessageBuilder
.withPayload("{\"id\":1,\"name\":\"wesley\"}")
.setHeader("contentType","application/json")
.build();
//@formatter:on
TenantStrategyJson tenantStrategyJson = new TenantStrategyJson(multitenancyConfigLoader);
String tenant = tenantStrategyJson.getValue(message);
Assert.assertEquals(tenantExpected, tenant);
}
示例10: when_execute_should_be_return_correct_tenant
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Test
public void when_execute_should_be_return_correct_tenant() {
String expectedValue = "clientId";
//@formatter:off
Message<?> message =
MessageBuilder
.withPayload("{tenant: 'clientId'}")
.setHeader("contentType", "application/json")
.build();
//@formatter:on
Mockito.when(tenantStrategy.getValue(Mockito.any())).thenReturn(expectedValue);
Mockito.when(tenantStrategyProvider.getStrategy(Mockito.any())).thenReturn(tenantStrategy);
SimpleTenantResolver str = new SimpleTenantResolver(mediaTypeResolver, tenantStrategyProvider);
String value = str.getValue(message);
Assert.assertEquals(expectedValue, value);
}
示例11: testEvaluation
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Override
protected void testEvaluation(Object input) throws InterruptedException {
Map<String, Object> inMap = new HashMap<>();
inMap.put("Placeholder", input);
Message<?> inputMessage = MessageBuilder
.withPayload("Dummy Payload")
.setHeader("myInputData", inMap)
.setHeader("passthrough", "passthrough")
.build();
channels.input().send(inputMessage);
Message<?> outputMessage = messageCollector.forChannel(channels.output()).poll(10, TimeUnit.SECONDS);
assertThat((String) outputMessage.getHeaders().get("passthrough"), equalTo("passthrough"));
assertThat((Float) outputMessage.getPayload(), equalTo(0.29999298f));
}
开发者ID:spring-cloud-stream-app-starters,项目名称:tensorflow,代码行数:21,代码来源:LinearRegressionTensorflowProcessorIntegrationTests.java
示例12: testSendAndReceive
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Test
@Override
public void testSendAndReceive() throws Exception {
RedisTestBinder binder = getBinder();
DirectChannel moduleOutputChannel = new DirectChannel();
QueueChannel moduleInputChannel = new QueueChannel();
ProducerProperties producerProperties = createProducerProperties();
producerProperties.setHeaderMode(HeaderMode.raw);
Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel, producerProperties);
ConsumerProperties consumerProperties = createConsumerProperties();
consumerProperties.setHeaderMode(HeaderMode.raw);
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "test", moduleInputChannel, consumerProperties);
Message<?> message = MessageBuilder.withPayload("foo".getBytes()).build();
// Let the consumer actually bind to the producer before sending a msg
binderBindUnbindLatency();
moduleOutputChannel.send(message);
Message<?> inbound = receive(moduleInputChannel);
assertNotNull(inbound);
assertEquals("foo", new String((byte[])inbound.getPayload()));
producerBinding.unbind();
consumerBinding.unbind();
}
示例13: handle
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
public void handle(Message<?> message){
Message<?> transformedMessage = message;
if (convertToJson) {
Object payload = message.getPayload();
if (payload instanceof String) {
PdxInstance transformedPayload = transformer.toObject((String)payload);
transformedMessage = MessageBuilder
.fromMessage(message)
.withPayload(transformedPayload)
.build();
}
else {
throw new MessageConversionException(String.format(
"Cannot convert object of type %s", payload.getClass()
.getName()));
}
}
messageHandler.handleMessage(transformedMessage);
}
示例14: testSpanPropagation
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Test
public void testSpanPropagation() {
Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler());
this.channel.send(MessageBuilder.withPayload("hi").build());
Long expectedSpanId = span.getSpanId();
this.tracer.close(span);
Message<?> message = this.channel.receive(0);
assertNotNull("message was null", message);
Long spanId = Span
.hexToId(message.getHeaders().get(Span.SPAN_ID_NAME, String.class));
assertNotEquals("spanId was equal to parent's id", expectedSpanId, spanId);
long traceId = Span
.hexToId(message.getHeaders().get(Span.TRACE_ID_NAME, String.class));
assertNotNull("traceId was null", traceId);
Long parentId = Span
.hexToId(message.getHeaders().get(Span.PARENT_ID_NAME, String.class));
assertEquals("parentId was not equal to parent's id", expectedSpanId, parentId);
}
示例15: testSingleMessageMultipleSubscribers
import org.springframework.integration.support.MessageBuilder; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void testSingleMessageMultipleSubscribers() throws Exception {
// create multiple handlers
List<WebsocketSinkClientHandler> handlers = createHandlerList(CLIENT_COUNT, 1);
// submit a single message
String payload = UUID.randomUUID().toString();
sink.input().send(MessageBuilder.withPayload(payload).build());
// await completion on each handler
for (WebsocketSinkClientHandler handler : handlers) {
handler.await();
assertThat(handler.receivedMessages.size(), is(1));
assertThat(handler.receivedMessages.get(0), is(payload));
}
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:18,代码来源:WebsocketSinkIntegrationTests.java