List of usage examples for org.springframework.messaging.support GenericMessage GenericMessage
public GenericMessage(T payload)
From source file:adapter.MessagingMessageListenerAdapterTests.java
@Test public void testFallbackType() { final class MyAdapter extends MessagingMessageListenerAdapter<String, String> implements AcknowledgingMessageListener<String, String> { private MyAdapter() { super(null, null); }/*from w w w . ja v a 2 s .c o m*/ @Override public void onMessage(ConsumerRecord<String, String> data, Acknowledgment acknowledgment) { toMessagingMessage(data, acknowledgment); } } MyAdapter adapter = new MyAdapter(); adapter.setFallbackType(String.class); RecordMessageConverter converter = mock(RecordMessageConverter.class); ConsumerRecord<String, String> cr = new ConsumerRecord<>("foo", 1, 1L, null, null); Acknowledgment ack = mock(Acknowledgment.class); willReturn(new GenericMessage<>("foo")).given(converter).toMessage(cr, ack, String.class); adapter.setMessageConverter(converter); adapter.onMessage(cr, ack); verify(converter).toMessage(cr, ack, String.class); }
From source file:io.spring.TaskSinkApplicationTests.java
@Test public void testLaunch() throws IOException { assertNotNull(this.sink.input()); TaskLauncher testTaskLauncher = context.getBean(TaskLauncher.class); Map<String, String> properties = new HashMap(); properties.put("server.port", "0"); TaskLaunchRequest request = new TaskLaunchRequest( "maven://org.springframework.cloud.task.app:" + "timestamp-task:jar:1.0.1.RELEASE", null, properties, null, null);//from w ww .j a v a2 s . c om GenericMessage<TaskLaunchRequest> message = new GenericMessage<TaskLaunchRequest>(request); this.sink.input().send(message); ArgumentCaptor<AppDeploymentRequest> deploymentRequest = ArgumentCaptor .forClass(AppDeploymentRequest.class); verify(testTaskLauncher).launch(deploymentRequest.capture()); AppDeploymentRequest actualRequest = deploymentRequest.getValue(); assertTrue(actualRequest.getCommandlineArguments().isEmpty()); assertEquals("0", actualRequest.getDefinition().getProperties().get("server.port")); assertTrue(actualRequest.getResource().toString() .contains("maven://org.springframework.cloud.task.app:timestamp-task:jar:1.0.1.RELEASE")); }
From source file:com.bigdata.log.LogSinkApplicationTests.java
@Test public void test() { assertNotNull(this.sink.input()); assertEquals(CustomLoggingHandler.Level.WARN, this.logSinkHandler.getLevel()); Log logger = TestUtils.getPropertyValue(this.logSinkHandler, "messageLogger", Log.class); assertEquals("foo", TestUtils.getPropertyValue(logger, "name")); logger = spy(logger);/* ww w . j a v a 2 s. com*/ new DirectFieldAccessor(this.logSinkHandler).setPropertyValue("messageLogger", logger); GenericMessage<String> message = new GenericMessage<>("foo"); this.sink.input().send(message); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); verify(logger).warn(captor.capture()); assertEquals("customized message for sample : FOO", captor.getValue()); this.logSinkHandler.setExpression("#this"); this.sink.input().send(message); verify(logger, times(2)).warn(captor.capture()); // assertSame(message, captor.getValue()); }
From source file:com.acme.ModuleConfigurationTest.java
@Test public void test() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); Properties properties = new Properties(); properties.put("prefix", "foo"); properties.put("suffix", "bar"); context.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("options", properties)); context.register(TestConfiguration.class); context.refresh();//from w w w .ja v a2 s . co m MessageChannel input = context.getBean("input", MessageChannel.class); SubscribableChannel output = context.getBean("output", SubscribableChannel.class); final AtomicBoolean handled = new AtomicBoolean(); output.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { handled.set(true); assertEquals("foohellobar", message.getPayload()); } }); input.send(new GenericMessage<String>("hello")); assertTrue(handled.get()); }
From source file:io.spring.TaskProcessor.java
@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()); }/* w ww .ja v a2 s. co m*/ 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); }
From source file:de.hybris.eventtracking.ws.controllers.rest.EventsController.java
protected void forwardForProcessing(final String payload) { final Message<String> message = new GenericMessage<String>(payload); rawTrackingEventsChannel.send(message); }
From source file:org.springframework.cloud.consul.bus.ConsulBusIT.java
@Test public void test003JsonToObject() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new SubtypeModule(SimpleRemoteEvent.class)); JsonToObjectTransformer transformer = Transformers.fromJson(RemoteApplicationEvent.class, new Jackson2JsonObjectMapper(objectMapper)); /*// w w w .j ava 2s. c o m * HashMap<String, Object> map = new HashMap<>(); map.put(JsonHeaders.TYPE_ID, * RemoteApplicationEvent.class); */ Message<?> message = transformer.transform(new GenericMessage<>(JSON_PAYLOAD)); Object payload = message.getPayload(); assertTrue("payload is of wrong type", payload instanceof RemoteApplicationEvent); assertTrue("payload is of wrong type", payload instanceof SimpleRemoteEvent); SimpleRemoteEvent event = (SimpleRemoteEvent) payload; assertEquals("payload is wrong", "testMessage", event.getMessage()); }
From source file:eric.bottard.tis100.Runner.java
public Runner(int rows, int columns, String specificationFile, File solution) throws IOException { Specification specification = new LuaSpecification(specificationFile, rows, columns); List<String> nodeSources = loadSolution(solution, specification.getLayout()); this.rows = rows; this.columns = columns; verticalChannels = new MessageChannel[columns * (rows + 1) * 2]; horizontalChannels = new MessageChannel[rows * (columns + 1) * 2]; // channels[2*x] = ltr / down-to-up // channels[2*x + 1] = rtl / up-to-down for (int row = 0; row <= rows; row++) { for (int column = 0; column < columns; column++) { verticalChannels[(row * columns + column) * 2] = (row == 0 || row == rows) ? new NullChannel() : new RendezvousChannel(); if (row == 0) { verticalChannels[(row * columns + column) * 2 + 1] = new QueueChannel(40); } else if (row == rows) { verticalChannels[(row * columns + column) * 2 + 1] = new PublishSubscribeChannel(); } else { verticalChannels[(row * columns + column) * 2 + 1] = new RendezvousChannel(); }/*from w w w.j a v a 2 s.c om*/ } } for (int row = 0; row < rows; row++) { for (int column = 0; column <= columns; column++) { horizontalChannels[(column * rows + row) * 2] = (column == 0 || column == columns) ? new NullChannel() : new RendezvousChannel(); horizontalChannels[(column * rows + row) * 2 + 1] = (column == 0 || column == columns) ? new NullChannel() : new RendezvousChannel(); } } Thread[] threads = new Thread[rows * columns]; Object mutex = new Object(); for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { final SpringNode node = NodeFactory.buildNode(nodeSources.get(row * columns + column)); final NodePrettyPrinter printer = new NodePrettyPrinter(4 + row * 19, SpecificationPrettyPrinter.WIDTH + 10 + column * 37, node); Ports ports = new PortsMapping(row, column); node.setPorts(ports); nodes.add(node); threads[row * columns + column] = new Thread() { @Override public void run() { boolean more; do { synchronized (mutex) { printer.draw(System.out); } try { Thread.sleep(150); } catch (InterruptedException e) { e.printStackTrace(); } more = node.tick(); } while (more); } }; } } List<Integer>[] actuals = new List[columns]; SpecificationPrettyPrinter specificationPrettyPrinter = new SpecificationPrettyPrinter(specification, 2, 2, actuals); for (int i = 0; i < columns; i++) { Specification.Stream stream = specification.getInputStreams()[i]; if (stream != null) { for (Integer in : stream.getData()) { verticalChannels[1 + 2 * i].send(new GenericMessage<>(in)); } } stream = specification.getOutputStreams()[i]; final List<Integer> actual = actuals[i] = new ArrayList<>(); if (stream != null) { ((SubscribableChannel) verticalChannels[1 + 2 * (i + rows * columns)]) .subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { actual.add((Integer) message.getPayload()); synchronized (mutex) { specificationPrettyPrinter.draw(System.out); } } }); } } synchronized (mutex) { specificationPrettyPrinter.draw(System.out); } for (int i = 0; i < rows * columns; i++) { threads[i].start(); } }
From source file:nl.rav.comparision.integration.unitofwork.java.UnitOfWorkSpringTest.java
private Message<?> sendMessage() { Message<String> message = new GenericMessage<String>("Hello, world!"); handler.handleMessage(message);//ww w .j av a 2s . com Message<?> reply = replies.receive(1000); completed = successChannel.receive(1000); failed = failureChannel.receive(1000); return reply; }
From source file:com.rabbitmq.client.impl.SocketFrameHandler.java
public void writeFrame(Frame frame) throws IOException { if (frame != null) { log.debug("writeFrame: addr(" + this.getAddress() + ":" + this.getPort() + "))]: " + frame + ": " + new String(frame.getPayload())); }//from w w w . jav a2 s .co m if (this.getPort() == RMQ_INSIDE) { RmqUdpFrame rmqUdpFrame = new RmqUdpFrame(++index, frame.channel, frame.type, frame.getPayload()); byte[] payload = SerializationUtils.serialize(rmqUdpFrame); log.info("rmq.frame.index(" + rmqUdpFrame.getIndex() + ").type(" + frame.type + ").channel(" + frame.channel + ").payload(" + frame.getPayload().length + ")"); try { unicastSendingMessageHandler.handleMessageInternal(new GenericMessage<byte[]>(payload)); Thread.sleep(WAIT_MILLIS); } catch (InterruptedException e) { e.printStackTrace(); } } synchronized (_outputStream) { frame.writeTo(_outputStream); } }