Java Code Examples for org.springframework.cloud.stream.binder.ProducerProperties#isUseNativeEncoding()

The following examples show how to use org.springframework.cloud.stream.binder.ProducerProperties#isUseNativeEncoding() . 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 File: KeyValueSerdeResolver.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
/**
 * Provide the {@link Serde} for outbound value.
 * @param producerProperties {@link ProducerProperties} on binding
 * @param kafkaStreamsProducerProperties binding level extended
 * {@link KafkaStreamsProducerProperties}
 * @return configurd {@link Serde} for the outbound value.
 */
public Serde<?> getOutboundValueSerde(ProducerProperties producerProperties,
		KafkaStreamsProducerProperties kafkaStreamsProducerProperties) {
	Serde<?> valueSerde;
	try {
		if (producerProperties.isUseNativeEncoding()) {
			valueSerde = getValueSerde(
					kafkaStreamsProducerProperties.getValueSerde());
		}
		else {
			valueSerde = Serdes.ByteArray();
		}
	}
	catch (ClassNotFoundException ex) {
		throw new IllegalStateException("Serde class not found: ", ex);
	}
	return valueSerde;
}
 
Example 2
Source File: KeyValueSerdeResolver.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
public Serde<?> getOutboundValueSerde(ProducerProperties producerProperties,
									KafkaStreamsProducerProperties kafkaStreamsProducerProperties, ResolvableType resolvableType) {
	Serde<?> valueSerde;
	try {
		if (producerProperties.isUseNativeEncoding()) {
			valueSerde = getValueSerde(
					kafkaStreamsProducerProperties.getValueSerde(), resolvableType);
		}
		else {
			valueSerde = Serdes.ByteArray();
		}
	}
	catch (ClassNotFoundException ex) {
		throw new IllegalStateException("Serde class not found: ", ex);
	}
	return valueSerde;
}
 
Example 3
Source File: MessageConverterConfigurer.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
private boolean isNativeEncodingNotSet(ProducerProperties producerProperties,
		ConsumerProperties consumerProperties, boolean input) {
	if (input) {
		return consumerProperties == null
				|| !consumerProperties.isUseNativeDecoding();
	}
	else {
		return producerProperties == null
				|| !producerProperties.isUseNativeEncoding();
	}
}
 
Example 4
Source File: FunctionConfiguration.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Bean
InitializingBean supplierInitializer(FunctionCatalog functionCatalog, StreamFunctionProperties functionProperties,
		GenericApplicationContext context, BindingServiceProperties serviceProperties,
		@Nullable BindableFunctionProxyFactory[] proxyFactories, StreamBridge streamBridge,
		TaskScheduler taskScheduler) {

	if (!ObjectUtils.isEmpty(context.getBeanNamesForAnnotation(EnableBinding.class)) || proxyFactories == null) {
		return null;
	}

	return new InitializingBean() {

		@Override
		public void afterPropertiesSet() throws Exception {
			for (BindableFunctionProxyFactory proxyFactory : proxyFactories) {
				FunctionInvocationWrapper functionWrapper = functionCatalog.lookup(proxyFactory.getFunctionDefinition());
				if (functionWrapper != null && functionWrapper.isSupplier()) {
					// gather output content types
					List<String> contentTypes = new ArrayList<String>();
					Assert.isTrue(proxyFactory.getOutputs().size() == 1, "Supplier with multiple outputs is not supported at the moment.");
					String outputName  = proxyFactory.getOutputs().iterator().next();

					BindingProperties bindingProperties = serviceProperties.getBindingProperties(outputName);
					ProducerProperties producerProperties = bindingProperties.getProducer();
					if (!(bindingProperties.getProducer() != null && producerProperties.isUseNativeEncoding())) {
						contentTypes.add(bindingProperties.getContentType());
					}

					// obtain function wrapper with proper output content types
					functionWrapper = functionCatalog.lookup(proxyFactory.getFunctionDefinition(), contentTypes.toArray(new String[0]));
					Publisher<Object> beginPublishingTrigger = setupBindingTrigger(context);

					if (!functionProperties.isComposeFrom() && !functionProperties.isComposeTo()) {
						String integrationFlowName = proxyFactory.getFunctionDefinition() + "_integrationflow";
						PollableBean pollable = extractPollableAnnotation(functionProperties, context, proxyFactory);

						Type functionType = functionWrapper.getFunctionType();
						IntegrationFlow integrationFlow = integrationFlowFromProvidedSupplier(new PartitionAwareFunctionWrapper(functionWrapper, context, producerProperties),
								beginPublishingTrigger, pollable, context, taskScheduler, functionType)
								.route(Message.class, message -> {
									if (message.getHeaders().get("spring.cloud.stream.sendto.destination") != null) {
										String destinationName = (String) message.getHeaders().get("spring.cloud.stream.sendto.destination");
										return streamBridge.resolveDestination(destinationName, producerProperties);
										//return dynamicDestinationResolver.resolveDestination(destinationName);
									}
									return outputName;
								}).get();
						IntegrationFlow postProcessedFlow = (IntegrationFlow) context.getAutowireCapableBeanFactory()
								.applyBeanPostProcessorsBeforeInitialization(integrationFlow, integrationFlowName);
						context.registerBean(integrationFlowName, IntegrationFlow.class, () -> postProcessedFlow);
					}
				}
			}
		}
	};
}