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


Java Source类代码示例

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


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

示例1: testSendBinaryDataWithContentType

import org.springframework.cloud.stream.messaging.Source; //导入依赖的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);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:19,代码来源:ContentTypeTests.java

示例2: testSendWithDefaultContentType

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testSendWithDefaultContentType() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false")) {

		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		User user = new User("Alice");
		source.output().send(MessageBuilder.withPayload(user).build());
		Message<String> message = (Message<String>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		User received = mapper.readValue(message.getPayload(), User.class);
		assertThat(
				message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
						.includes(MimeTypeUtils.APPLICATION_JSON));
		assertThat(user.getName()).isEqualTo(received.getName());
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:20,代码来源:ContentTypeTests.java

示例3: testSendJsonAsString

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testSendJsonAsString() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false")) {
		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		User user = new User("Alice");
		String json = mapper.writeValueAsString(user);
		source.output().send(MessageBuilder.withPayload(user).build());
		Message<String> message = (Message<String>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		assertThat(
				message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
						.includes(MimeTypeUtils.APPLICATION_JSON));
		assertThat(json).isEqualTo(message.getPayload());
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:19,代码来源:ContentTypeTests.java

示例4: testSendJsonString

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testSendJsonString() throws Exception{
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false")) {
		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		source.output().send(MessageBuilder.withPayload("foo").build());
		Message<String> message = (Message<String>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		assertThat(
				message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
						.includes(MimeTypeUtils.APPLICATION_JSON));
		assertThat("foo").isEqualTo(message.getPayload());
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:17,代码来源:ContentTypeTests.java

示例5: testSendBynaryData

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testSendBynaryData() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false")) {

		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).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_OCTET_STREAM).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.APPLICATION_OCTET_STREAM));
		assertThat(message.getPayload()).isEqualTo(data);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:19,代码来源:ContentTypeTests.java

示例6: testSendBinaryDataWithContentTypeUsingHeaders

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testSendBinaryDataWithContentTypeUsingHeaders() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false")) {
		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)
				.setHeader(MessageHeaders.CONTENT_TYPE,MimeTypeUtils.IMAGE_JPEG)
				.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);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:19,代码来源:ContentTypeTests.java

示例7: testSendJavaSerializable

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testSendJavaSerializable() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false",
			"--spring.cloud.stream.bindings.output.contentType=application/x-java-serialized-object")) {
		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		User user = new User("Alice");
		source.output().send(MessageBuilder.withPayload(user).build());
		Message<User> message = (Message<User>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
				.includes(MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT));
		User received = message.getPayload();
		assertThat(user.getName()).isEqualTo(received.getName());
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:19,代码来源:ContentTypeTests.java

示例8: testSendKryoSerialized

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testSendKryoSerialized() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false",
			"--spring.cloud.stream.bindings.output.contentType=application/x-java-object")) {
		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		User user = new User("Alice");
		source.output().send(MessageBuilder.withPayload(user).build());
		Message<User> message = (Message<User>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		User received = message.getPayload();
		assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
				.includes(MimeType.valueOf(KryoMessageConverter.KRYO_MIME_TYPE)));
		assertThat(user.getName()).isEqualTo(received.getName());

	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:20,代码来源:ContentTypeTests.java

示例9: testSendStringType

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testSendStringType() throws Exception{
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false",
			"--spring.cloud.stream.bindings.output.contentType=text/plain")) {
		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		User user = new User("Alice");
		source.output().send(MessageBuilder.withPayload(user).build());
		Message<String> message = (Message<String>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
				.includes(MimeTypeUtils.TEXT_PLAIN));
		assertThat(message.getPayload()).isEqualTo(user.toString());
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:18,代码来源:ContentTypeTests.java

示例10: testSendTuple

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testSendTuple() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false",
			"--spring.cloud.stream.bindings.output.contentType=application/x-spring-tuple")) {
		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		Tuple tuple = TupleBuilder.tuple().of("foo","bar");
		source.output().send(MessageBuilder.withPayload(tuple).build());
		Message<byte[]> message = (Message<byte[]>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
				.includes(MessageConverterUtils.X_SPRING_TUPLE));
		assertThat(TupleBuilder.fromString(new String(message.getPayload()))).isEqualTo(tuple);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:18,代码来源:ContentTypeTests.java

示例11: testCustomNamingStrategy

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Test
public void testCustomNamingStrategy() throws Exception {
	ConfigurableApplicationContext sourceContext = SpringApplication.run(AvroSourceApplication.class,
		"--server.port=0",
		"--debug",
		"--spring.jmx.enabled=false",
		"--spring.cloud.stream.bindings.output.contentType=application/*+avro",
		"--spring.cloud.stream.schema.avro.subjectNamingStrategy=org.springframework.cloud.schema.avro.CustomSubjectNamingStrategy",
		"--spring.cloud.stream.schema.avro.dynamicSchemaGenerationEnabled=true");

	Source source = sourceContext.getBean(Source.class);
	User1 user1 = new User1();
	user1.setFavoriteColor("foo" + UUID.randomUUID().toString());
	user1.setName("foo" + UUID.randomUUID().toString());
	source.output().send(MessageBuilder.withPayload(user1).build());

	MessageCollector barSourceMessageCollector = sourceContext.getBean(MessageCollector.class);
	Message<?> message = barSourceMessageCollector.forChannel(source.output()).poll(1000, TimeUnit.MILLISECONDS);

	assertThat(message.getHeaders().get("contentType"))
			.isEqualTo(MimeType.valueOf("application/vnd.org.springframework.cloud.schema.avro.User1.v1+avro"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:23,代码来源:SubjectNamingStrategyTest.java

示例12: mqttInbound

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Bean
public MqttPahoMessageDrivenChannelAdapter mqttInbound() {
	MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(properties.getClientId(),
			mqttClientFactory, properties.getTopics());
	adapter.setQos(properties.getQos());
	adapter.setConverter(pahoMessageConverter());
	adapter.setOutputChannelName(Source.OUTPUT);
	return adapter;
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:mqtt,代码行数:10,代码来源:MqttSourceConfiguration.java

示例13: stockPriceChangeEvent

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "60000", maxMessagesPerPoll = "1"))
public MessageSource<StockPriceChangeEvent> stockPriceChangeEvent() {

	StockTicker[] tickers = StockTicker.values();
	String randomStockTicker = tickers[ThreadLocalRandom.current().nextInt(tickers.length)].name();

	return () -> {
		StockPriceChangeEvent event = new StockPriceChangeEvent(randomStockTicker,
				new BigDecimal(getRandomNumber(10, 20)), new BigDecimal(getRandomNumber(10, 20)));

		logger.info("sending " + event);
		return MessageBuilder.withPayload(event).build();
	};
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Spring-5.0,代码行数:16,代码来源:SignificantStockChangeSourceApplication.java

示例14: mailInboundFlow

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Bean
public IntegrationFlow mailInboundFlow() {
	return getFlowBuilder()
			.transform(Mail.toStringTransformer(this.properties.getCharset()))
			.enrichHeaders(h -> {
				h.defaultOverwrite(true)
						.header(MailHeaders.TO, arrayToListProcessor(MailHeaders.TO))
						.header(MailHeaders.CC, arrayToListProcessor(MailHeaders.CC))
						.header(MailHeaders.BCC, arrayToListProcessor(MailHeaders.BCC));
			})
			.channel(Source.OUTPUT)
			.get();
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:mail,代码行数:14,代码来源:MailSourceConfiguration.java

示例15: loggregatorMessageSource

import org.springframework.cloud.stream.messaging.Source; //导入依赖的package包/类
@Bean
public LoggregatorMessageSource loggregatorMessageSource(
		@Qualifier(Source.OUTPUT) MessageChannel source,
		CloudFoundryClient cloudFoundryClient) {
	return new LoggregatorMessageSource(
			this.loggregatorSourceProperties.getApplicationName(),
			cloudFoundryClient, source);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:9,代码来源:LoggregatorSourceConfiguration.java


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