當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。