Java Code Examples for org.springframework.cloud.stream.messaging.Source

The following examples show how to use org.springframework.cloud.stream.messaging.Source. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-cloud-stream   Source File: ContentTypeTests.java    License: Apache License 2.0 6 votes vote down vote up
@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());
	}
}
 
Example 2
Source Project: spring-cloud-stream   Source File: ContentTypeTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 = this.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());
	}
}
 
Example 3
Source Project: spring-cloud-stream   Source File: ContentTypeTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 = this.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());
	}
}
 
Example 4
Source Project: spring-cloud-stream   Source File: ContentTypeTests.java    License: Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example 5
Source Project: spring-cloud-stream   Source File: ContentTypeTests.java    License: Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example 6
Source Project: spring-cloud   Source File: DataProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "10000", maxMessagesPerPoll = "1"))
public MessageSource<TimeInfo> timerMessageSource() {
    return () -> MessageBuilder.withPayload(
            TimeInfo.builder().time(Long.toString(System.currentTimeMillis())).label(UUID.randomUUID().toString()).build())
            .build();
}
 
Example 7
@StreamEmitter
@Output(Source.OUTPUT)
public Flux<MessageResponse> getMessagesStream() {
    return webClient.get()
                    .uri(GitterUriBuilder.from(gitterProperties.getStream())
                                         .build()
                                         .toUri())
                    .retrieve()
                    .bodyToFlux(MessageResponse.class)
                    .retryBackoff(Long.MAX_VALUE, Duration.ofMillis(500));
}
 
Example 8
@SneakyThrows
@StreamEmitter
@Output(Source.OUTPUT)
public Flux<MessageResponse> getLatestMessages() {
    return webClient.get()
                    .uri(GitterUriBuilder.from(gitterProperties.getApi())
                                         .build()
                                         .toUri())
                    .retrieve()
                    .bodyToFlux(MessageResponse.class)
                    .timeout(Duration.ofSeconds(1))
                    .retryBackoff(Long.MAX_VALUE, Duration.ofMillis(500));
}
 
Example 9
@Test
public void testChannelTypes() throws Exception {
	DirectWithAttributesChannel inputChannel = (DirectWithAttributesChannel) this.testSink
			.input();
	DirectWithAttributesChannel outputChannel = (DirectWithAttributesChannel) this.testSource
			.output();
	assertThat(inputChannel.getAttribute("type")).isEqualTo(Sink.INPUT);
	assertThat(outputChannel.getAttribute("type")).isEqualTo(Source.OUTPUT);
}
 
Example 10
@Publisher( channel = Source.OUTPUT )
public Message<String> sendNotification( Tuple event ) {

    String payload = converter.convert( event );

    return MessageBuilder
            .withPayload( payload )
            .setHeader( "x-delay", 1000 )
            .build();
}
 
Example 11
Source Project: training   Source File: ReservationClientApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
RouterFunction<ServerResponse> routes(WebClient client,
																																						Source src) {
		return route(GET("/reservations/names"), req -> {

				Flux<String> names = client
					.get()
					.uri("http://reservation-service/reservations")
					.retrieve()
					.bodyToFlux(Reservation.class)
					.map(Reservation::getReservationName);

				Publisher<String> fallback = HystrixCommands
					.from(names)
					.commandName("reservation-names")
					.fallback(Flux.just("EEK!"))
					.eager()
					.build();

				return ServerResponse.ok().body(fallback, String.class);
		})
			.andRoute(POST("/reservations"), req -> {
						Flux<Boolean> sendResult = req.bodyToFlux(Reservation.class)
							.map(Reservation::getReservationName)
							.map(r -> MessageBuilder.withPayload(r).build())
							.map(msg -> src.output().send(msg));
						return ServerResponse.ok().body(sendResult, Boolean.class);
				}
			);
}
 
Example 12
Source Project: training   Source File: ReservationClientApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
RouterFunction<ServerResponse> routes(WebClient client,
                                      Source src) {
	return route(GET("/reservations/names"), req -> {

		Flux<String> names = client
				.get()
				.uri("http://reservation-service/reservations")
				.retrieve()
				.bodyToFlux(Reservation.class)
				.map(Reservation::getReservationName);

		Publisher<String> fallback = HystrixCommands
				.from(names)
				.commandName("reservation-names")
				.fallback(Flux.just("EEK!"))
				.eager()
				.build();

		return ServerResponse.ok().body(fallback, String.class);
	})
			.andRoute(POST("/reservations"), req -> {
						Flux<Boolean> sendResult = req.bodyToFlux(Reservation.class)
								.map(Reservation::getReservationName)
								.map(r -> MessageBuilder.withPayload(r).build())
								.map(msg -> src.output().send(msg));
						return ServerResponse.ok().body(sendResult, Boolean.class);
					}
			);
}
 
Example 13
Source Project: mqtt   Source File: MqttSourceConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 14
@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();
	};
}
 
Example 15
@Bean
public LoggregatorMessageSource loggregatorMessageSource(
		@Qualifier(Source.OUTPUT) MessageChannel source,
		CloudFoundryClient cloudFoundryClient) {
	return new LoggregatorMessageSource(
			this.loggregatorSourceProperties.getApplicationName(),
			cloudFoundryClient, source);
}
 
Example 16
@Bean
public IntegrationFlow s3InboundFlow(FileConsumerProperties fileConsumerProperties,
		S3InboundFileSynchronizer s3InboundFileSynchronizer) {
	S3InboundFileSynchronizingMessageSource s3MessageSource =
			new S3InboundFileSynchronizingMessageSource(s3InboundFileSynchronizer);
	s3MessageSource.setLocalDirectory(this.s3SourceProperties.getLocalDir());
	s3MessageSource.setAutoCreateLocalDirectory(this.s3SourceProperties.isAutoCreateLocalDir());

	return FileUtils.enhanceFlowForReadingMode(IntegrationFlows.from(s3MessageSource), fileConsumerProperties)
			.channel(Source.OUTPUT)
			.get();
}
 
Example 17
@Bean
public IntegrationFlow mailInboundFlow() {
	return getFlowBuilder()
			.transform(Transformers.fromMail(this.properties.getCharset()))
			.channel(Source.OUTPUT)
			.get();
}
 
Example 18
@Test
public void testS3Source() throws IOException, InterruptedException {
	String bucket = "TestBucket";
	String key = "foo";
	String content = "Spring Cloud Stream AWS S3 Source test";

	this.applicationContext = SpringApplication.run(S3SourceBootConfiguration.class,
			"--s3.remoteDir=" + bucket, "--file.consumer.mode=lines", "--file.consumer.with-markers=false");

	ResourceIdResolver resourceIdResolver = this.applicationContext.getBean(ResourceIdResolver.class);

	AmazonS3 amazonS3 = this.applicationContext.getBean(AmazonS3.class);
	ObjectMetadata objectMetadata = new ObjectMetadata();
	objectMetadata.setContentLength(content.length());
	String bucketName = resourceIdResolver.resolveToPhysicalResourceId(bucket);
	amazonS3.putObject(bucketName, key, new ByteArrayInputStream(content.getBytes("UTF-8")), objectMetadata);

	try {
		Source source = this.applicationContext.getBean(Source.class);
		MessageCollector messageCollector = this.applicationContext.getBean(MessageCollector.class);
		Message<?> received = messageCollector.forChannel(source.output()).poll(10, TimeUnit.SECONDS);
		assertNotNull(received);
		assertThat(received, hasHeader(FileHeaders.FILENAME, key));
		assertThat(received, hasPayload("Spring Cloud Stream AWS S3 Source test"));
	}
	finally {
		amazonS3.deleteObject(bucketName, key);
	}
}
 
Example 19
@Override
public SubscribableChannel createOutput(String name) {
	DirectWithAttributesChannel subscribableChannel = new DirectWithAttributesChannel();
	subscribableChannel.setComponentName(name);
	subscribableChannel.setAttribute("type", Source.OUTPUT);
	this.messageChannelConfigurer.configureOutputChannel(subscribableChannel, name);
	if (context != null && !context.containsBean(name)) {
		context.registerBean(name, DirectWithAttributesChannel.class, () -> subscribableChannel);
	}
	return subscribableChannel;
}
 
Example 20
@Bean
public IntegrationFlow messageSourceFlow(Source source) {
	Supplier<Message<String>> messageSource = () -> MessageBuilder
			.withPayload("hello function")
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
			.build();
	return IntegrationFlows.from(messageSource).channel(source.output()).get();
}
 
Example 21
@Bean
public HttpRequestHandlingEndpointSupport doFoo(Source source) {
	HttpRequestHandlerEndpointSpec httpRequestHandler = Http
			.inboundChannelAdapter("/*")
			.requestMapping(requestMapping -> requestMapping
					.methods(HttpMethod.POST).consumes("*/*"))
			.requestChannel(source.output());
	return httpRequestHandler.get();
}
 
Example 22
@Test
public void testCustomPartitionedProducer() {
	ApplicationContext context = SpringApplication.run(
			CustomPartitionedProducerTest.TestSource.class,
			"--spring.jmx.enabled=false", "--spring.main.web-application-type=none",
			"--spring.cloud.stream.bindings.output.producer.partitionKeyExtractorClass="
					+ "org.springframework.cloud.stream.partitioning.CustomPartitionKeyExtractorClass",
			"--spring.cloud.stream.bindings.output.producer.partitionSelectorClass="
					+ "org.springframework.cloud.stream.partitioning.CustomPartitionSelectorClass",
			"--spring.cloud.stream.default-binder=mock");
	Source testSource = context.getBean(Source.class);
	DirectChannel messageChannel = (DirectChannel) testSource.output();
	for (ChannelInterceptor channelInterceptor : messageChannel
			.getInterceptors()) {
		if (channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) {
			Field partitionHandlerField = ReflectionUtils.findField(
					MessageConverterConfigurer.PartitioningInterceptor.class,
					"partitionHandler");
			ReflectionUtils.makeAccessible(partitionHandlerField);
			PartitionHandler partitionHandler = (PartitionHandler) ReflectionUtils
					.getField(partitionHandlerField, channelInterceptor);
			Field partitonKeyExtractorField = ReflectionUtils.findField(
					PartitionHandler.class, "partitionKeyExtractorStrategy");
			ReflectionUtils.makeAccessible(partitonKeyExtractorField);
			Field partitonSelectorField = ReflectionUtils
					.findField(PartitionHandler.class, "partitionSelectorStrategy");
			ReflectionUtils.makeAccessible(partitonSelectorField);
			assertThat(((PartitionKeyExtractorStrategy) ReflectionUtils
					.getField(partitonKeyExtractorField, partitionHandler)).getClass()
							.equals(CustomPartitionKeyExtractorClass.class)).isTrue();
			assertThat(((PartitionSelectorStrategy) ReflectionUtils
					.getField(partitonSelectorField, partitionHandler)).getClass()
							.equals(CustomPartitionSelectorClass.class)).isTrue();
		}
	}
}
 
Example 23
@Test
public void testCustomPartitionedProducerByName() {
	ApplicationContext context = SpringApplication.run(
			CustomPartitionedProducerTest.TestSource.class,
			"--spring.jmx.enabled=false", "--spring.main.web-application-type=none",
			"--spring.cloud.stream.bindings.output.producer.partitionKeyExtractorName=customPartitionKeyExtractor",
			"--spring.cloud.stream.bindings.output.producer.partitionSelectorName=customPartitionSelector",
			"--spring.cloud.stream.default-binder=mock");
	Source testSource = context.getBean(Source.class);
	DirectChannel messageChannel = (DirectChannel) testSource.output();
	for (ChannelInterceptor channelInterceptor : messageChannel
			.getInterceptors()) {
		if (channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) {
			Field partitionHandlerField = ReflectionUtils.findField(
					MessageConverterConfigurer.PartitioningInterceptor.class,
					"partitionHandler");
			ReflectionUtils.makeAccessible(partitionHandlerField);
			PartitionHandler partitionHandler = (PartitionHandler) ReflectionUtils
					.getField(partitionHandlerField, channelInterceptor);
			Field partitonKeyExtractorField = ReflectionUtils.findField(
					PartitionHandler.class, "partitionKeyExtractorStrategy");
			ReflectionUtils.makeAccessible(partitonKeyExtractorField);
			Field partitonSelectorField = ReflectionUtils
					.findField(PartitionHandler.class, "partitionSelectorStrategy");
			ReflectionUtils.makeAccessible(partitonSelectorField);
			assertThat(((PartitionKeyExtractorStrategy) ReflectionUtils
					.getField(partitonKeyExtractorField, partitionHandler)).getClass()
							.equals(CustomPartitionKeyExtractorClass.class)).isTrue();
			assertThat(((PartitionSelectorStrategy) ReflectionUtils
					.getField(partitonSelectorField, partitionHandler)).getClass()
							.equals(CustomPartitionSelectorClass.class)).isTrue();
		}
	}
}
 
Example 24
@Test
public void testCustomPartitionedProducerAsSingletons() {
	ApplicationContext context = SpringApplication.run(
			CustomPartitionedProducerTest.TestSource.class,
			"--spring.jmx.enabled=false", "--spring.main.web-application-type=none",
			"--spring.cloud.stream.default-binder=mock");
	Source testSource = context.getBean(Source.class);
	DirectChannel messageChannel = (DirectChannel) testSource.output();
	for (ChannelInterceptor channelInterceptor : messageChannel
			.getInterceptors()) {
		if (channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) {
			Field partitionHandlerField = ReflectionUtils.findField(
					MessageConverterConfigurer.PartitioningInterceptor.class,
					"partitionHandler");
			ReflectionUtils.makeAccessible(partitionHandlerField);
			PartitionHandler partitionHandler = (PartitionHandler) ReflectionUtils
					.getField(partitionHandlerField, channelInterceptor);
			Field partitonKeyExtractorField = ReflectionUtils.findField(
					PartitionHandler.class, "partitionKeyExtractorStrategy");
			ReflectionUtils.makeAccessible(partitonKeyExtractorField);
			Field partitonSelectorField = ReflectionUtils
					.findField(PartitionHandler.class, "partitionSelectorStrategy");
			ReflectionUtils.makeAccessible(partitonSelectorField);
			assertThat(((PartitionKeyExtractorStrategy) ReflectionUtils
					.getField(partitonKeyExtractorField, partitionHandler)).getClass()
							.equals(CustomPartitionKeyExtractorClass.class)).isTrue();
			assertThat(((PartitionSelectorStrategy) ReflectionUtils
					.getField(partitonSelectorField, partitionHandler)).getClass()
							.equals(CustomPartitionSelectorClass.class)).isTrue();
		}
	}
}
 
Example 25
public void testCustomPartitionedProducerMultipleInstances() {
	ApplicationContext context = SpringApplication.run(
			CustomPartitionedProducerTest.TestSourceMultipleStrategies.class,
			"--spring.jmx.enabled=false", "--spring.main.web-application-type=none",
			"--spring.cloud.stream.bindings.output.producer.partitionKeyExtractorName=customPartitionKeyExtractorOne",
			"--spring.cloud.stream.bindings.output.producer.partitionSelectorName=customPartitionSelectorTwo",
			"--spring.cloud.stream.default-binder=mock");
	Source testSource = context.getBean(Source.class);
	DirectChannel messageChannel = (DirectChannel) testSource.output();
	for (ChannelInterceptor channelInterceptor : messageChannel
			.getInterceptors()) {
		if (channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) {
			Field partitionHandlerField = ReflectionUtils.findField(
					MessageConverterConfigurer.PartitioningInterceptor.class,
					"partitionHandler");
			ReflectionUtils.makeAccessible(partitionHandlerField);
			PartitionHandler partitionHandler = (PartitionHandler) ReflectionUtils
					.getField(partitionHandlerField, channelInterceptor);
			Field partitonKeyExtractorField = ReflectionUtils.findField(
					PartitionHandler.class, "partitionKeyExtractorStrategy");
			ReflectionUtils.makeAccessible(partitonKeyExtractorField);
			Field partitonSelectorField = ReflectionUtils
					.findField(PartitionHandler.class, "partitionSelectorStrategy");
			ReflectionUtils.makeAccessible(partitonSelectorField);
			assertThat(((PartitionKeyExtractorStrategy) ReflectionUtils
					.getField(partitonKeyExtractorField, partitionHandler)).getClass()
							.equals(CustomPartitionKeyExtractorClass.class)).isTrue();
			assertThat(((PartitionSelectorStrategy) ReflectionUtils
					.getField(partitonSelectorField, partitionHandler)).getClass()
							.equals(CustomPartitionSelectorClass.class)).isTrue();
		}
	}
}
 
Example 26
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
public MessageSource<String> timerMessageSource() {
	return new MessageSource<String>() {
		@Override
		public Message<String> receive() {
			throw new MessagingException("test");
		}
	};
}
 
Example 27
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
public MessageSource<String> timerMessageSource() {
	return new MessageSource<String>() {
		@Override
		public Message<String> receive() {
			throw new MessagingException("test");
		}
	};
}
 
Example 28
@Test
public void testGlobalPropertiesSet() {
	BindingProperties bindingProperties = this.bindingServiceProperties
			.getBindingProperties(Source.OUTPUT);
	Assertions.assertThat(bindingProperties.getContentType())
			.isEqualTo("application/json");
	Assertions.assertThat(bindingProperties.getProducer()).isNotNull();
	Assertions.assertThat(bindingProperties.getProducer().getPartitionKeyExpression()
			.getExpressionString()).isEqualTo("key");
}
 
Example 29
@Test
public void testGlobalPropertiesSet() {
	BindingProperties bindingProperties = this.serviceProperties
			.getBindingProperties(Source.OUTPUT);
	Assertions.assertThat(bindingProperties.getContentType())
			.isEqualTo("application/json");
	Assertions.assertThat(bindingProperties.getDestination()).isEqualTo("ticktock");
	Assertions.assertThat(bindingProperties.getProducer().getRequiredGroups())
			.containsExactly("someGroup"); // default propagates to producer
	Assertions.assertThat(bindingProperties.getProducer().getPartitionCount())
			.isEqualTo(4); // validates binding property takes precedence over default
	Assertions.assertThat(bindingProperties.getProducer().getHeaderMode())
			.isEqualTo(HeaderMode.none);
}
 
Example 30
Source Project: spring-cloud-stream   Source File: ContentTypeTests.java    License: Apache License 2.0 5 votes vote down vote up
@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.getPayload()).isEqualTo(data);
	}
}