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


Java GenericMessage类代码示例

本文整理汇总了Java中org.springframework.messaging.support.GenericMessage的典型用法代码示例。如果您正苦于以下问题:Java GenericMessage类的具体用法?Java GenericMessage怎么用?Java GenericMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GenericMessage类属于org.springframework.messaging.support包,在下文中一共展示了GenericMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void test() throws Exception {
	assertThat(this.splitter, instanceOf(FileSplitter.class));
	assertSame(this.splitter, TestUtils.getPropertyValue(this.consumer, "handler"));
	File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "splitter.proc.test");
	FileOutputStream fos = new FileOutputStream(file);
	fos.write("hello\nworld\n".getBytes());
	fos.close();
	this.channels.input().send(new GenericMessage<>(file));
	Message<?> m = this.collector.forChannel(this.channels.output()).poll(10, TimeUnit.SECONDS);
	assertNotNull(m);
	assertThat(m.getPayload(), instanceOf(FileMarker.class));
	assertThat((FileMarker) m.getPayload(), hasMark(Mark.START));
	assertThat(m, allOf(hasSequenceNumber(1), hasSequenceSize(0)));
	assertThat(this.collector.forChannel(this.channels.output()), receivesPayloadThat(is("hello")));
	assertThat(this.collector.forChannel(this.channels.output()), receivesPayloadThat(is("world")));
	assertThat(this.collector.forChannel(this.channels.output()),
			receivesPayloadThat(allOf(
					instanceOf(FileMarker.class),
		 			hasMark(Mark.END))));
	file.delete();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:23,代码来源:SplitterProcessorIntegrationTests.java

示例2: testWithKey

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void testWithKey() throws Exception{
	//Setup
	String key = "foo";
	StringRedisTemplate redisTemplate = createStringRedisTemplate(redisConnectionFactory);
	redisTemplate.delete(key);

	RedisList<String> redisList = new DefaultRedisList<String>(key, redisTemplate);
	List<String> list = new ArrayList<String>();
	list.add("Manny");
	list.add("Moe");
	list.add("Jack");

	//Execute
	Message<List<String>> message = new GenericMessage<List<String>>(list);
	sink.input().send(message);

	//Assert
	assertEquals(3, redisList.size());
	assertEquals("Manny", redisList.get(0));
	assertEquals("Moe", redisList.get(1));
	assertEquals("Jack", redisList.get(2));

	//Cleanup
	redisTemplate.delete(key);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:27,代码来源:RedisSinkApplicationTests.java

示例3: spyOn

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Override
public Spy spyOn(final String queue) {
	final RedisTemplate<String, Object> template = createTemplate();
	return new Spy() {

		@Override
		public Object receive(boolean expectNull) throws Exception {
			byte[] bytes = (byte[]) template.boundListOps(queue).rightPop(50, TimeUnit.MILLISECONDS);
			if (bytes == null) {
				return null;
			}
			bytes = (byte[]) embeddedHeadersMessageConverter.extractHeaders(new GenericMessage<byte[]>(bytes), false).getPayload();
			return new String(bytes, "UTF-8");
		}

	};
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:18,代码来源:RedisBinderTests.java

示例4: testCustomMessageSerializer

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void testCustomMessageSerializer() throws Exception {
	RedisTemplate<String, Message<?>> template = new RedisTemplate<>();
	template.setKeySerializer(new StringRedisSerializer());
	template.setValueSerializer(new TestMessageSerializer());
	template.setConnectionFactory(connectionFactory);
	template.afterPropertiesSet();

	adapter.setSerializer(new TestMessageSerializer());
	adapter.setExpectMessage(true);
	adapter.afterPropertiesSet();
	adapter.start();

	template.boundListOps(currentQueueName).rightPush(new GenericMessage<>(10l));
	@SuppressWarnings("unchecked")
	Message<Long> message = (Message<Long>) messages.poll((int)(1000 * timeoutMultiplier), TimeUnit.MILLISECONDS);
	assertEquals(10L, (long) message.getPayload());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:19,代码来源:RedisQueueInboundChannelAdapterTests.java

示例5: testIngestQuery

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void testIngestQuery() throws Exception {
	List<Book> books = getBookList(5);

	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
	Jackson2JsonObjectMapper mapper = new Jackson2JsonObjectMapper(objectMapper);

	this.sink.input().send(new GenericMessage<>(mapper.toJson(books)));

	final Select select = QueryBuilder.select().all().from("book");

	assertEqualsEventually(5, new Supplier<Integer>() {

		@Override
		public Integer get() {
			return cassandraTemplate.select(select, Book.class).size();
		}

	});

	this.cassandraTemplate.truncate("book");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:24,代码来源:CassandraSinkIntegrationTests.java

示例6: testDefaultMsgSerializer

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void testDefaultMsgSerializer() throws Exception {
	RedisTemplate<String, Message<?>> template = new RedisTemplate<String, Message<?>>();
	template.setKeySerializer(new StringRedisSerializer());
	template.setValueSerializer(new JdkSerializationRedisSerializer());
	template.setConnectionFactory(connectionFactory);
	template.afterPropertiesSet();

	adapter.setExtractPayload(false);
	adapter.afterPropertiesSet();

	Map<String, Object> headers = new HashMap<String, Object>();
	headers.put("header1", "foo");
	adapter.handleMessage(new GenericMessage<String>("message2", headers));
	Message<?> message = template.boundListOps(QUEUE_NAME).rightPop();
	assertEquals("message2", message.getPayload());
	assertEquals("foo", message.getHeaders().get("header1"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:19,代码来源:RedisQueueOutboundChannelAdapterTests.java

示例7: shouldPublishMessageWithError

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void shouldPublishMessageWithError() {

    // given
    reset(hermesSender);
    final HermesResponse response = HermesResponseBuilder.hermesResponse()
            .withHttpStatus(500)
            .build();

    when(hermesSender.send(any(URI.class), any(HermesMessage.class)))
            .thenReturn(CompletableFuture.completedFuture(response));

    DirectChannel output = new DirectChannel();

    // when
    Binding<MessageChannel> binding = binder.bindProducer(
            OUTPUT_NAME, output, new ExtendedProducerProperties<>(new HermesProducerProperties()));

    // then
    output.send(new GenericMessage<>(MESSAGE, json()));
    verify(hermesSender, times(4)).send(any(URI.class), any(HermesMessage.class));
    binding.unbind();
}
 
开发者ID:jmnarloch,项目名称:hermes-spring-cloud-starter-stream,代码行数:24,代码来源:HermesClientBinderTest.java

示例8: logs

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@RequestMapping(value = "/logs", method = RequestMethod.POST)
@ResponseBody
public String logs(@RequestBody String body) throws IOException {

  // "application/logplex-1" does not conform to RFC5424.
  // It leaves out STRUCTURED-DATA but does not replace it with
  // a NILVALUE. To workaround this, we inject empty STRUCTURED-DATA.
  String[] parts = body.split("router - ");
  String log = parts[0] + "router - [] " + (parts.length > 1 ? parts[1] : "");

  RFC6587SyslogDeserializer parser = new RFC6587SyslogDeserializer();
  InputStream is = new ByteArrayInputStream(log.getBytes());
  Map<String, ?> messages = parser.deserialize(is);
  ObjectMapper mapper = new ObjectMapper();

  MessageChannel toKafka = context.getBean("toKafka", MessageChannel.class);
  String json = mapper.writeValueAsString(messages);
  toKafka.send(new GenericMessage<>(json));

  return "ok";
}
 
开发者ID:jkutner,项目名称:heroku-metrics-spring,代码行数:22,代码来源:MainController.java

示例9: testInsert

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void testInsert() throws InterruptedException {
	Book book = new Book();
	book.setIsbn(UUIDs.timeBased());
	book.setTitle("Spring Integration Cassandra");
	book.setAuthor("Cassandra Guru");
	book.setPages(521);
	book.setSaleDate(new Date());
	book.setInStock(true);

	this.sink.input().send(new GenericMessage<>(book));

	final Select select = QueryBuilder.select().all().from("book");

	assertEqualsEventually(1, new Supplier<Integer>() {

		@Override
		public Integer get() {
			return cassandraTemplate.select(select, Book.class).size();
		}

	});

	this.cassandraTemplate.delete(book);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:26,代码来源:CassandraSinkIntegrationTests.java

示例10: sendFiles

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void sendFiles() {
	for (int i = 1; i <= 2; i++) {
		String pathname = "/localSource" + i + ".txt";
		String upperPathname = pathname.toUpperCase();
		new File(getTargetRemoteDirectory() + upperPathname).delete();
		assertFalse(new File(getTargetRemoteDirectory() + upperPathname).exists());
		this.ftpSink.input().send(new GenericMessage<>(new File(getSourceLocalDirectory() + pathname)));
		File expected = new File(getTargetRemoteDirectory() + upperPathname);
		assertTrue(expected.getAbsolutePath() + " does not exist", expected.exists());
		// verify the upcase on a case-insensitive file system
		File[] files = getTargetRemoteDirectory().listFiles();
		for (File file : files) {
			assertThat(file.getName(), startsWith("LOCALSOURCE"));
		}
	}
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:ftp,代码行数:18,代码来源:FtpSinkIntegrationTests.java

示例11: testIntegration

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void testIntegration() throws Exception {
  MessageChannel producingChannel =
      applicationContext.getBean("producingChannel", MessageChannel.class);

  Map<String, Object> headers =
      Collections.singletonMap(KafkaHeaders.TOPIC, SPRING_INTEGRATION_KAFKA_TOPIC);

  LOGGER.info("sending 10 messages");
  for (int i = 0; i < 10; i++) {
    GenericMessage<String> message =
        new GenericMessage<>("Hello Spring Integration Kafka " + i + "!", headers);
    producingChannel.send(message);
    LOGGER.info("sent message='{}'", message);
  }

  countDownLatchHandler.getLatch().await(10000, TimeUnit.MILLISECONDS);
  assertThat(countDownLatchHandler.getLatch().getCount()).isEqualTo(0);
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:20,代码来源:SpringKafkaIntegrationApplicationTest.java

示例12: test

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void test() {
	assertNotNull(this.sink.input());
	assertEquals(LoggingHandler.Level.WARN, this.logSinkHandler.getLevel());
	Log logger = TestUtils.getPropertyValue(this.logSinkHandler, "messageLogger",
			Log.class);
	assertEquals("foo", TestUtils.getPropertyValue(logger, "name"));
	logger = spy(logger);
	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("FOO", captor.getValue());
	this.logSinkHandler.setExpression("#this");
	this.sink.input().send(message);
	verify(logger, times(2)).warn(captor.capture());
	assertSame(message, captor.getValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:21,代码来源:LogSinkApplicationTests.java

示例13: setUp

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Before
public void setUp() {
	this.message = new GenericMessage<>("testPayload",
			ImmutableMap.of("key1", "value1", "key2", "value2"));
	SettableListenableFuture<String> future = new SettableListenableFuture<>();
	future.set("benfica");
	when(this.pubSubTemplate.publish(eq("testTopic"),
			eq(ByteString.copyFrom("testPayload", Charset.defaultCharset())),
			isA(Map.class)))
			.thenReturn(future);
	this.adapter = new PubSubMessageHandler(this.pubSubTemplate, "testTopic");

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:14,代码来源:PubSubMessageHandlerTests.java

示例14: testNewFiles

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Test
public void testNewFiles() throws IOException {
	File testFile = this.temporaryFolder.newFile("benfica");

	BlobInfo expectedCreateBlobInfo =
			BlobInfo.newBuilder(BlobId.of("testGcsBucket", "benfica.writing")).build();
	WriteChannel writeChannel = mock(WriteChannel.class);
	willAnswer(invocationOnMock -> writeChannel).given(GCS)
			.writer(eq(expectedCreateBlobInfo));
	willAnswer(invocationOnMock -> 10).given(writeChannel).write(isA(ByteBuffer.class));

	CopyWriter copyWriter = mock(CopyWriter.class);
	ArgumentCaptor<Storage.CopyRequest> copyRequestCaptor = ArgumentCaptor.forClass(Storage.CopyRequest.class);
	willAnswer(invocationOnMock -> copyWriter).given(GCS).copy(isA(Storage.CopyRequest.class));

	willAnswer(invocationOnMock -> true).given(GCS)
			.delete(eq(BlobId.of("testGcsBucket", "benfica.writing")));

	this.channel.send(new GenericMessage<Object>(testFile));

	verify(GCS, times(1)).writer(eq(expectedCreateBlobInfo));
	verify(GCS, times(1)).copy(copyRequestCaptor.capture());
	verify(GCS, times(1)).delete(eq(BlobId.of("testGcsBucket", "benfica.writing")));

	Storage.CopyRequest expectedCopyRequest = copyRequestCaptor.getValue();
	assertThat(expectedCopyRequest.getSource()).isEqualTo(BlobId.of("testGcsBucket", "benfica.writing"));
	assertThat(expectedCopyRequest.getTarget().getBlobId()).isEqualTo(BlobId.of("testGcsBucket", "benfica"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:29,代码来源:GcsMessageHandlerTests.java

示例15: setUp

import org.springframework.messaging.support.GenericMessage; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    HashMap<String, Object> headerMap = new HashMap<>();
    headerMap.put("MessageId", "mid");
    headerMap.put("Acknowledgment", acknowledgment);
    message = new GenericMessage<>(3, new MessageHeaders(headerMap));
    uut = new MessageHandlingRunnable<>(worker, message, finishedMessageCallback, messages,
            visibilityTimeoutExtender);
}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:11,代码来源:MessageHandlingRunnableTest.java


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