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


Java ProducerDestination类代码示例

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


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

示例1: createProducerMessageHandler

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Override
protected MessageHandler createProducerMessageHandler(ProducerDestination destination,
		ExtendedProducerProperties<KinesisProducerProperties> producerProperties, MessageChannel errorChannel) {

	KinesisMessageHandler kinesisMessageHandler = new KinesisMessageHandler(this.amazonKinesis);
	kinesisMessageHandler.setSync(producerProperties.getExtension().isSync());
	kinesisMessageHandler.setSendTimeout(producerProperties.getExtension().getSendTimeout());
	kinesisMessageHandler.setStream(destination.getName());
	if (producerProperties.isPartitioned()) {
		kinesisMessageHandler
				.setPartitionKeyExpressionString("'partitionKey-' + headers." + BinderHeaders.PARTITION_HEADER);
	}
	kinesisMessageHandler.setFailureChannel(errorChannel);
	kinesisMessageHandler.setBeanFactory(getBeanFactory());

	return kinesisMessageHandler;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-aws-kinesis,代码行数:18,代码来源:KinesisMessageChannelBinder.java

示例2: testProvisionProducerSuccessfulWithExistingStream

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Test
public void testProvisionProducerSuccessfulWithExistingStream() {
	AmazonKinesis amazonKinesisMock = mock(AmazonKinesis.class);
	KinesisBinderConfigurationProperties binderProperties = new KinesisBinderConfigurationProperties();
	KinesisStreamProvisioner provisioner = new KinesisStreamProvisioner(amazonKinesisMock, binderProperties);
	ExtendedProducerProperties<KinesisProducerProperties> extendedProducerProperties =
			new ExtendedProducerProperties<>(new KinesisProducerProperties());
	String name = "test-stream";

	DescribeStreamResult describeStreamResult = describeStreamResultWithShards(
			Collections.singletonList(new Shard()));

	when(amazonKinesisMock.describeStream(any(DescribeStreamRequest.class)))
			.thenReturn(describeStreamResult);

	ProducerDestination destination = provisioner.provisionProducerDestination(name, extendedProducerProperties);

	verify(amazonKinesisMock)
			.describeStream(any(DescribeStreamRequest.class));

	assertThat(destination.getName()).isEqualTo(name);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-aws-kinesis,代码行数:23,代码来源:KinesisStreamProvisionerTests.java

示例3: provisionProducerDestination

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Override
public ProducerDestination provisionProducerDestination(final String name, ExtendedProducerProperties<KafkaProducerProperties> properties) {
	if (this.logger.isInfoEnabled()) {
		this.logger.info("Using kafka topic for outbound: " + name);
	}
	KafkaTopicUtils.validateTopicName(name);
	createTopic(name, properties.getPartitionCount(), false);
	if (this.configurationProperties.isAutoCreateTopics() && adminClient != null) {
		DescribeTopicsResult describeTopicsResult = adminClient.describeTopics(Collections.singletonList(name));
		KafkaFuture<Map<String, TopicDescription>> all = describeTopicsResult.all();

		try {
			Map<String, TopicDescription> topicDescriptions = all.get(operationTimeout, TimeUnit.SECONDS);
			TopicDescription topicDescription = topicDescriptions.get(name);
			int partitions = topicDescription.partitions().size();
			return new KafkaProducerDestination(name, partitions);
		}
		catch (Exception e) {
			throw new ProvisioningException("Problems encountered with partitions finding", e);
		}
	}
	else {
		return new KafkaProducerDestination(name);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:26,代码来源:KafkaTopicProvisioner.java

示例4: destroyErrorInfrastructure

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
private void destroyErrorInfrastructure(ProducerDestination destination) {
	String errorChannelName = errorsBaseName(destination);
	String errorBridgeHandlerName = getErrorBridgeName(destination);
	MessageHandler bridgeHandler = null;
	if (getApplicationContext().containsBean(errorBridgeHandlerName)) {
		bridgeHandler = getApplicationContext().getBean(errorBridgeHandlerName, MessageHandler.class);
	}
	if (getApplicationContext().containsBean(errorChannelName)) {
		SubscribableChannel channel = getApplicationContext().getBean(errorChannelName, SubscribableChannel.class);
		if (bridgeHandler != null) {
			channel.unsubscribe(bridgeHandler);
			((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
					.destroySingleton(errorBridgeHandlerName);
		}
		((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
				.destroySingleton(errorChannelName);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:19,代码来源:AbstractMessageChannelBinder.java

示例5: provisionProducerDestination

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Override
public ProducerDestination provisionProducerDestination(String name,
		ExtendedProducerProperties<KinesisProducerProperties> properties) throws ProvisioningException {

	if (logger.isInfoEnabled()) {
		logger.info("Using Kinesis stream for outbound: " + name);
	}

	if (properties.getHeaderMode() == null) {
		properties.setHeaderMode(HeaderMode.embeddedHeaders);
	}

	return new KinesisProducerDestination(name, createOrUpdate(name, properties.getPartitionCount()));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-aws-kinesis,代码行数:15,代码来源:KinesisStreamProvisioner.java

示例6: testProvisionProducerSuccessfulWithNewStream

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Test
public void testProvisionProducerSuccessfulWithNewStream() {
	AmazonKinesis amazonKinesisMock = mock(AmazonKinesis.class);
	KinesisBinderConfigurationProperties binderProperties = new KinesisBinderConfigurationProperties();
	KinesisStreamProvisioner provisioner = new KinesisStreamProvisioner(amazonKinesisMock, binderProperties);
	ExtendedProducerProperties<KinesisProducerProperties> extendedProducerProperties =
			new ExtendedProducerProperties<>(new KinesisProducerProperties());

	String name = "test-stream";
	Integer shards = 1;

	DescribeStreamResult describeStreamResult =
			describeStreamResultWithShards(Collections.singletonList(new Shard()));

	when(amazonKinesisMock.describeStream(any(DescribeStreamRequest.class)))
			.thenThrow(new ResourceNotFoundException("I got nothing"))
			.thenReturn(describeStreamResult);

	when(amazonKinesisMock.createStream(name, shards))
			.thenReturn(new CreateStreamResult());

	ProducerDestination destination = provisioner.provisionProducerDestination(name, extendedProducerProperties);

	verify(amazonKinesisMock, times(2))
			.describeStream(any(DescribeStreamRequest.class));

	verify(amazonKinesisMock)
			.createStream(name, shards);

	assertThat(destination.getName()).isEqualTo(name);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-aws-kinesis,代码行数:32,代码来源:KinesisStreamProvisionerTests.java

示例7: createProducerMessageHandler

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Override
protected MessageHandler createProducerMessageHandler(ProducerDestination destination,
		ExtendedProducerProperties<PubSubProducerProperties> producerProperties,
		MessageChannel errorChannel) throws Exception {

	this.provisioningProvider.provisionProducerDestination(
			destination.getName(), producerProperties);

	return new PubSubMessageHandler(this.pubSubTemplate, destination.getName());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:11,代码来源:PubSubMessageChannelBinder.java

示例8: provisionProducerDestination

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Override
public ProducerDestination provisionProducerDestination(String name,
		ExtendedProducerProperties<PubSubProducerProperties> properties)
		throws ProvisioningException {
	if (this.pubSubAdmin.getTopic(name) == null) {
		this.pubSubAdmin.createTopic(name);
	}

	return new PubSubProducerDestination(name);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:11,代码来源:PubSubChannelProvisioner.java

示例9: provisionProducerDestination

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Override
public ProducerDestination provisionProducerDestination(String name,
		ExtendedProducerProperties<JmsProducerProperties> properties) throws ProvisioningException {
	logger.info("Provisioning producer destination: '{}'", name);

	Collection<DestinationNames> topicAndQueueNames = this.destinationNameResolver
			.resolveTopicAndQueueNameForRequiredGroups(name, properties);

	final Map<Integer, Topic> partitionTopics = new HashMap<>();

	for (DestinationNames destinationNames : topicAndQueueNames) {
		String sanitisedTopicName = sanitiseObjectName(destinationNames.getTopicName());
		Topic topic = ibmMQRequests.createTopic(sanitisedTopicName);
		for (String queue : destinationNames.getGroupNames()) {
			// format for the subscribing queue name is: 'topic'.'queue'
			String sanitisedQueueName = sanitiseObjectName(String.format("%s.%s", sanitisedTopicName, queue));
			ibmMQRequests.createQueue(sanitisedQueueName);
			ibmMQRequests.subcribeQueueToTopic(sanitisedTopicName, sanitisedQueueName);
		}

		if (destinationNames.getPartitionIndex() != null) {
			partitionTopics.put(destinationNames.getPartitionIndex(), topic);
		}
		else {
			partitionTopics.put(-1, topic);
		}
	}

	return new JmsProducerDestination(partitionTopics);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-ibm-mq,代码行数:31,代码来源:IBMMQProvisioningProvider.java

示例10: createProducerMessageHandler

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Override
protected MessageHandler createProducerMessageHandler(ProducerDestination destination,
		ProducerProperties producerProperties, MessageChannel errorChannel) throws Exception {
	BridgeHandler handler = new BridgeHandler();
	handler.setBeanFactory(this.beanFactory);
	handler.setOutputChannel(((SpringIntegrationProducerDestination)destination).getChannel());
	return handler;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:9,代码来源:SpringIntegrationChannelBinder.java

示例11: createProducerMessageHandler

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Override
protected MessageHandler createProducerMessageHandler(final ProducerDestination destination,
		ExtendedProducerProperties<KafkaProducerProperties> producerProperties, MessageChannel errorChannel)
		throws Exception {
	/*
	 * IMPORTANT: With a transactional binder, individual producer properties for Kafka are
	 * ignored; the global binder (spring.cloud.stream.kafka.binder.transaction.producer.*)
	 * properties are used instead, for all producers. A binder is transactional when
	 * 'spring.cloud.stream.kafka.binder.transaction.transaction-id-prefix' has text.
	 */
	final ProducerFactory<byte[], byte[]> producerFB = this.transactionManager != null
			? this.transactionManager.getProducerFactory()
			: getProducerFactory(null, producerProperties);
	Collection<PartitionInfo> partitions = provisioningProvider.getPartitionsForTopic(
			producerProperties.getPartitionCount(), false,
			() -> {
				Producer<byte[], byte[]> producer = producerFB.createProducer();
				List<PartitionInfo> partitionsFor = producer.partitionsFor(destination.getName());
				producer.close();
				((DisposableBean) producerFB).destroy();
				return partitionsFor;
			});
	this.topicsInUse.put(destination.getName(), new TopicInformation(null, partitions));
	if (producerProperties.getPartitionCount() < partitions.size()) {
		if (this.logger.isInfoEnabled()) {
			this.logger.info("The `partitionCount` of the producer for topic " + destination.getName() + " is "
					+ producerProperties.getPartitionCount() + ", smaller than the actual partition count of "
					+ partitions.size() + " of the topic. The larger number will be used instead.");
		}
		/*
		 * This is dirty; it relies on the fact that we, and the partition interceptor, share a
		 * hard reference to the producer properties instance. But I don't see another way to fix
		 * it since the interceptor has already been added to the channel, and we don't have
		 * access to the channel here; if we did, we could inject the proper partition count
		 * there. TODO: Consider this when doing the 2.0 binder restructuring.
		 */
		producerProperties.setPartitionCount(partitions.size());
	}

	KafkaTemplate<byte[], byte[]> kafkaTemplate = new KafkaTemplate<>(producerFB);
	if (this.producerListener != null) {
		kafkaTemplate.setProducerListener(this.producerListener);
	}
	ProducerConfigurationMessageHandler handler = new ProducerConfigurationMessageHandler(kafkaTemplate,
			destination.getName(), producerProperties, producerFB);
	if (errorChannel != null) {
		handler.setSendFailureChannel(errorChannel);
	}
	KafkaHeaderMapper mapper = null;
	if (this.configurationProperties.getHeaderMapperBeanName() != null) {
		mapper = getApplicationContext().getBean(this.configurationProperties.getHeaderMapperBeanName(),
				KafkaHeaderMapper.class);
	}
	/*
	 *  Even if the user configures a bean, we must not use it if the header
	 *  mode is not the default (headers); setting the mapper to null
	 *  disables populating headers in the message handler.
	 */
	if (producerProperties.getHeaderMode() != null
			&& !HeaderMode.headers.equals(producerProperties.getHeaderMode())) {
		mapper = null;
	}
	else if (mapper == null) {
		String[] headerPatterns = producerProperties.getExtension().getHeaderPatterns();
		if (headerPatterns != null && headerPatterns.length > 0) {
			List<String> patterns = new LinkedList<>(Arrays.asList(headerPatterns));
			if (!patterns.contains("!" + MessageHeaders.TIMESTAMP)) {
				patterns.add(0, "!" + MessageHeaders.TIMESTAMP);
			}
			if (!patterns.contains("!" + MessageHeaders.ID)) {
				patterns.add(0, "!" + MessageHeaders.ID);
			}
			mapper = new DefaultKafkaHeaderMapper(patterns.toArray(new String[patterns.size()]));
		}
		else {
			mapper = new DefaultKafkaHeaderMapper();
		}
	}
	handler.setHeaderMapper(mapper);
	return handler;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:82,代码来源:KafkaMessageChannelBinder.java

示例12: createProducerMessageHandler

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
@Override
protected MessageHandler createProducerMessageHandler(final ProducerDestination producerDestination,
		ExtendedProducerProperties<RabbitProducerProperties> producerProperties, MessageChannel errorChannel) {
	Assert.state(!HeaderMode.embeddedHeaders.equals(producerProperties.getHeaderMode()),
			"the RabbitMQ binder does not support embedded headers since RabbitMQ supports headers natively");
	String prefix = producerProperties.getExtension().getPrefix();
	String exchangeName = producerDestination.getName();
	String destination = StringUtils.isEmpty(prefix) ? exchangeName : exchangeName.substring(prefix.length());
	final AmqpOutboundEndpoint endpoint = new AmqpOutboundEndpoint(
			buildRabbitTemplate(producerProperties.getExtension(), errorChannel != null));
	endpoint.setExchangeName(producerDestination.getName());
	RabbitProducerProperties extendedProperties = producerProperties.getExtension();
	boolean expressionInterceptorNeeded = expressionInterceptorNeeded(extendedProperties);
	String routingKeyExpression = extendedProperties.getRoutingKeyExpression();
	if (!producerProperties.isPartitioned()) {
		if (routingKeyExpression == null) {
			endpoint.setRoutingKey(destination);
		}
		else {
			if (expressionInterceptorNeeded) {
				endpoint.setRoutingKeyExpressionString("headers['"
						+ RabbitExpressionEvaluatingInterceptor.ROUTING_KEY_HEADER + "']");
			}
			else {
				endpoint.setRoutingKeyExpressionString(routingKeyExpression);
			}
		}
	}
	else {
		if (routingKeyExpression == null) {
			endpoint.setRoutingKeyExpressionString(buildPartitionRoutingExpression(destination, false));
		}
		else {
			if (expressionInterceptorNeeded) {
				endpoint.setRoutingKeyExpressionString(buildPartitionRoutingExpression("headers['"
						+ RabbitExpressionEvaluatingInterceptor.ROUTING_KEY_HEADER + "']", true));
			}
			else {
				endpoint.setRoutingKeyExpressionString(buildPartitionRoutingExpression(routingKeyExpression,
						true));
			}
		}
	}
	if (extendedProperties.getDelayExpression() != null) {
		if (expressionInterceptorNeeded) {
			endpoint.setDelayExpressionString("headers['"
					+ RabbitExpressionEvaluatingInterceptor.DELAY_HEADER + "']");
		}
		else {
			endpoint.setDelayExpressionString(extendedProperties.getDelayExpression());
		}
	}
	DefaultAmqpHeaderMapper mapper = DefaultAmqpHeaderMapper.outboundMapper();
	List<String> headerPatterns = new ArrayList<>(extendedProperties.getHeaderPatterns().length + 1);
	headerPatterns.add("!" + BinderHeaders.PARTITION_HEADER);
	headerPatterns.addAll(Arrays.asList(extendedProperties.getHeaderPatterns()));
	mapper.setRequestHeaderNames(headerPatterns.toArray(new String[headerPatterns.size()]));
	endpoint.setHeaderMapper(mapper);
	endpoint.setDefaultDeliveryMode(extendedProperties.getDeliveryMode());
	endpoint.setBeanFactory(this.getBeanFactory());
	if (errorChannel != null) {
		checkConnectionFactoryIsErrorCapable();
		endpoint.setReturnChannel(errorChannel);
		endpoint.setConfirmNackChannel(errorChannel);
		endpoint.setConfirmCorrelationExpressionString("#root");
		endpoint.setErrorMessageStrategy(new DefaultErrorMessageStrategy());
	}
	endpoint.afterPropertiesSet();
	return endpoint;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-rabbit,代码行数:71,代码来源:RabbitMessageChannelBinder.java

示例13: getErrorBridgeName

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
protected String getErrorBridgeName(ProducerDestination destination) {
	return errorsBaseName(destination) + ".bridge";
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:4,代码来源:AbstractMessageChannelBinder.java

示例14: errorsBaseName

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
protected String errorsBaseName(ProducerDestination destination) {
	return destination.getName() + ".errors";
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:4,代码来源:AbstractMessageChannelBinder.java

示例15: provisionProducerDestination

import org.springframework.cloud.stream.provisioning.ProducerDestination; //导入依赖的package包/类
/**
 * Will provision producer destination as an SI {@link PublishSubscribeChannel}.
 * <br>
 * This provides convenience of registering additional subscriber (handler in the test method)
 * along side of being able to call {@link TargetDestination#receive()} to get a
 * {@link Message} for additional assertions.
 */
@Override
public ProducerDestination provisionProducerDestination(String name, ProducerProperties properties) throws ProvisioningException {
	SubscribableChannel destination = this.provisionDestination(name, true);
	this.target.setChannel(destination);
	return new SpringIntegrationProducerDestination(name, destination);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:14,代码来源:SpringIntegrationProvisioner.java


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