本文整理汇总了Java中org.springframework.cloud.stream.messaging.Processor类的典型用法代码示例。如果您正苦于以下问题:Java Processor类的具体用法?Java Processor怎么用?Java Processor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Processor类属于org.springframework.cloud.stream.messaging包,在下文中一共展示了Processor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformer
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@Bean
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public MessageProcessor<?> transformer() {
String language = this.properties.getLanguage();
String script = this.properties.getScript();
logger.info(String.format("Input script is '%s', language is '%s'", script, language));
Resource scriptResource = new ByteArrayResource(decodeScript(script).getBytes()) {
// TODO until INT-3976
@Override
public String getFilename() {
// Only the groovy script processor enforces this requirement for a name
return "StaticScript";
}
};
return Scripts.script(scriptResource)
.lang(language)
.variableGenerator(this.scriptVariableGenerator)
.get();
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:22,代码来源:ScriptableTransformProcessorConfiguration.java
示例2: testMessageArgument
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testMessageArgument() throws Exception {
ConfigurableApplicationContext context = SpringApplication
.run(this.configClass, "--server.port=0", "--spring.cloud.stream.bindings.output.contentType=text/plain","--spring.jmx.enabled=false");
MessageCollector collector = context.getBean(MessageCollector.class);
Processor processor = context.getBean(Processor.class);
String id = UUID.randomUUID().toString();
processor.input().send(MessageBuilder.withPayload("barbar" + id)
.setHeader("contentType", "text/plain").build());
TestPojoWithMessageArgument testPojoWithMessageArgument = context
.getBean(TestPojoWithMessageArgument.class);
assertThat(testPojoWithMessageArgument.receivedMessages).hasSize(1);
assertThat(testPojoWithMessageArgument.receivedMessages.get(0).getPayload()).isEqualTo("barbar" + id);
Message<String> message = (Message<String>) collector
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
assertThat(message).isNotNull();
assertThat(message.getPayload()).contains("barbar" + id);
context.close();
}
示例3: testMethodWithObjectAsMethodArgument
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testMethodWithObjectAsMethodArgument() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(TestMethodWithObjectAsMethodArgument.class,
"--server.port=0",
"--spring.jmx.enabled=false",
"--spring.cloud.stream.bindings.input.contentType=text/plain",
"--spring.cloud.stream.bindings.output.contentType=text/plain");
Processor processor = context.getBean(Processor.class);
final String testMessage = "testing";
processor.input().send(MessageBuilder.withPayload(testMessage).build());
MessageCollector messageCollector = context.getBean(MessageCollector.class);
Message<String> result = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo(testMessage.toUpperCase());
context.close();
}
示例4: testMethodHeadersPropagatged
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
/**
* @since 2.0 : This test is an example of the new behavior of 2.0 when it comes to contentType handling.
* The default contentType being JSON in order to be able to check a message without quotes the user needs to set the input/output contentType accordingly
* Also, received messages are always of Message<byte[]> now.
*/
public void testMethodHeadersPropagatged() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(TestMethodHeadersPropagated.class,
"--server.port=0",
"--spring.jmx.enabled=false",
"--spring.cloud.stream.bindings.input.contentType=text/plain",
"--spring.cloud.stream.bindings.output.contentType=text/plain");
Processor processor = context.getBean(Processor.class);
final String testMessage = "testing";
processor.input().send(MessageBuilder.withPayload(testMessage)
.setHeader("foo", "bar")
.build());
MessageCollector messageCollector = context.getBean(MessageCollector.class);
Message<String> result = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo(testMessage.toUpperCase());
assertThat(result.getHeaders().get("foo")).isEqualTo("bar");
context.close();
}
示例5: testMethodWithMultipleInputParameters
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@Test
public void testMethodWithMultipleInputParameters() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(TestMethodWithMultipleInputParameters.class,
"--server.port=0",
"--spring.jmx.enabled=false");
Processor processor = context.getBean(Processor.class);
StreamListenerTestUtils.FooInboundChannel1 inboundChannel2 = context
.getBean(StreamListenerTestUtils.FooInboundChannel1.class);
final CountDownLatch latch = new CountDownLatch(2);
((SubscribableChannel) processor.output()).subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
Assert.isTrue(message.getPayload().equals("footesting") || message.getPayload().equals("BARTESTING"), "Assert failed");
latch.countDown();
}
});
processor.input().send(MessageBuilder.withPayload("{\"foo\":\"fooTESTing\"}")
.setHeader("contentType", "application/json").build());
inboundChannel2.input().send(MessageBuilder.withPayload("{\"bar\":\"bartestING\"}")
.setHeader("contentType", "application/json").build());
assertThat(latch.await(1, TimeUnit.SECONDS));
context.close();
}
示例6: receive
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@StreamListener
public void receive(@Input(Processor.INPUT) SubscribableChannel input,
@Output(Processor.OUTPUT) final MessageChannel output1,
@Output(StreamListenerTestUtils.FooOutboundChannel1.OUTPUT) final MessageChannel output2) {
input.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
if (message.getHeaders().get("output").equals("output1")) {
output1.send(org.springframework.messaging.support.MessageBuilder
.withPayload(message.getPayload().toString().toUpperCase()).build());
}
else if (message.getHeaders().get("output").equals("output2")) {
output2.send(org.springframework.messaging.support.MessageBuilder
.withPayload(message.getPayload().toString().toLowerCase()).build());
}
}
});
}
示例7: setupRequest
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Object setupRequest(String message) {
Map<String, String> properties = new HashMap<String,String>();
if(StringUtils.hasText(processorProperties.getDataSourceUrl())){
properties.put("spring_datasource_url",processorProperties.getDataSourceUrl());
}
if(StringUtils.hasText(processorProperties.getDataSourceDriverClassName())){
properties.put("spring_datasource_driverClassName",processorProperties.getDataSourceDriverClassName());
}
if(StringUtils.hasText(processorProperties.getDataSourceUserName())){
properties.put("spring_datasource_username",processorProperties.getDataSourceUserName());
}
if(StringUtils.hasText(processorProperties.getDataSourcePassword())){
properties.put("spring_datasource_password",processorProperties.getDataSourcePassword());
}
properties.put("payload", message);
TaskLaunchRequest request = new TaskLaunchRequest(
processorProperties.getUri(), null, properties, null,
processorProperties.getApplicationName());
return new GenericMessage<TaskLaunchRequest>(request);
}
示例8: testHandlerBean
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testHandlerBean() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(this.configClass,
"--spring.cloud.stream.bindings.output.contentType=application/json",
"--server.port=0");
MessageCollector collector = context.getBean(MessageCollector.class);
Processor processor = context.getBean(Processor.class);
String id = UUID.randomUUID().toString();
processor.input().send(
MessageBuilder.withPayload("{\"foo\":\"barbar" + id + "\"}")
.setHeader("contentType", "application/json").build());
HandlerBean handlerBean = context.getBean(HandlerBean.class);
Assertions.assertThat(handlerBean.receivedPojos).hasSize(1);
Assertions.assertThat(handlerBean.receivedPojos.get(0)).hasFieldOrPropertyWithValue("foo",
"barbar" + id);
Message<String> message = (Message<String>) collector.forChannel(
processor.output()).poll(1, TimeUnit.SECONDS);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("{\"bar\":\"barbar" + id + "\"}");
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
.includes(MimeTypeUtils.APPLICATION_JSON));
context.close();
}
示例9: testReturnConversion
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testReturnConversion() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(this.configClass,
"--spring.cloud.stream.bindings.output.contentType=application/json", "--server.port=0","--spring.jmx.enabled=false");
MessageCollector collector = context.getBean(MessageCollector.class);
Processor processor = context.getBean(Processor.class);
String id = UUID.randomUUID().toString();
processor.input().send(MessageBuilder.withPayload("{\"foo\":\"barbar" + id + "\"}")
.setHeader("contentType", "application/json").build());
TestPojoWithMimeType testPojoWithMimeType = context.getBean(TestPojoWithMimeType.class);
Assertions.assertThat(testPojoWithMimeType.receivedPojos).hasSize(1);
Assertions.assertThat(testPojoWithMimeType.receivedPojos.get(0)).hasFieldOrPropertyWithValue("foo", "barbar" + id);
Message<String> message = (Message<String>) collector.forChannel(processor.output()).poll(1,
TimeUnit.SECONDS);
assertThat(message).isNotNull();
assertThat(new String(message.getPayload())).isEqualTo("{\"bar\":\"barbar" + id + "\"}");
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
.includes(MimeTypeUtils.APPLICATION_JSON));
context.close();
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:22,代码来源:StreamListenerMethodReturnWithConversionTests.java
示例10: testReturnNoConversion
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testReturnNoConversion() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(this.configClass, "--server.port=0","--spring.jmx.enabled=false");
MessageCollector collector = context.getBean(MessageCollector.class);
Processor processor = context.getBean(Processor.class);
String id = UUID.randomUUID().toString();
processor.input().send(MessageBuilder.withPayload("{\"foo\":\"barbar" + id + "\"}")
.setHeader("contentType", "application/json").build());
TestPojoWithMimeType testPojoWithMimeType = context.getBean(TestPojoWithMimeType.class);
Assertions.assertThat(testPojoWithMimeType.receivedPojos).hasSize(1);
Assertions.assertThat(testPojoWithMimeType.receivedPojos.get(0)).hasFieldOrPropertyWithValue("foo", "barbar" + id);
Message<String> message = (Message<String>) collector
.forChannel(processor.output()).poll(1,
TimeUnit.SECONDS);
assertThat(message).isNotNull();
StreamListenerTestUtils.BarPojo barPojo = mapper.readValue(message.getPayload(),StreamListenerTestUtils.BarPojo.class);
assertThat(barPojo.getBar()).isEqualTo("barbar" + id);
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class) != null);
context.close();
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:22,代码来源:StreamListenerMethodReturnWithConversionTests.java
示例11: save
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@StreamListener
@Output(Processor.OUTPUT)
public Flux<Comment> save(@Input(Processor.INPUT) Flux<Comment> newComment) {
return repository
.saveAll(newComment)
.map(comment -> {
meterRegistry
.counter("comments.consumed", "imageId", comment.getImageId())
.increment();
return comment;
});
}
示例12: save
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@StreamListener
@Output(Processor.OUTPUT)
public Flux<Comment> save(@Input(Processor.INPUT) Flux<Comment> newComment) {
return repository
.saveAll(newComment)
.map(comment -> {
log.info("Saving new comment " + comment);
meterRegistry
.counter("comments.consumed", "imageId", comment.getImageId())
.increment();
return comment;
});
}
示例13: save
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@StreamListener
@Output(Processor.OUTPUT)
public Flux<Void> save(@Input(Processor.INPUT) Flux<Comment> newComment) {
return repository
.saveAll(newComment)
.flatMap(comment -> {
meterRegistry
.counter("comments.consumed", "imageId", comment.getImageId())
.increment();
return Mono.empty();
});
}
示例14: verifyEmpString
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@StreamListener
@Output(Processor.OUTPUT)
public Flux<String> verifyEmpString(@Input(Processor.INPUT) Flux<String> id) {
System.out.println("first");
id.delayElements(Duration.ofMillis(2))
.log();
return id;
}
示例15: evaluate
import org.springframework.cloud.stream.messaging.Processor; //导入依赖的package包/类
@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Message<?> evaluate(Message<?> input) {
Map<String, Object> processorContext = new ConcurrentHashMap<>();
Map<String, Object> inputData = tensorflowInputConverter.convert(input, processorContext);
Tensor outputTensor = tensorFlowService.evaluate(
inputData, properties.getOutputName(), properties.getOutputIndex());
Object outputData = tensorflowOutputConverter.convert(outputTensor, processorContext);
if (properties.isSaveOutputInHeader()) {
// Add the result to the message header
return MessageBuilder
.withPayload(input.getPayload())
.copyHeadersIfAbsent(input.getHeaders())
.setHeaderIfAbsent(TF_OUTPUT_HEADER, outputData)
.build();
}
// Add the outputData as part of the message payload
Message<?> outputMessage = MessageBuilder
.withPayload(outputData)
.copyHeadersIfAbsent(input.getHeaders())
.build();
return outputMessage;
}
开发者ID:tzolov,项目名称:tensorflow-spring-cloud-stream-app-starters,代码行数:30,代码来源:TensorflowProcessorConfiguration.java