Java Code Examples for org.springframework.cloud.stream.provisioning.ConsumerDestination#getName()

The following examples show how to use org.springframework.cloud.stream.provisioning.ConsumerDestination#getName() . 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: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiplexOnPartitionedConsumer() throws Exception {
	final ExtendedConsumerProperties<RabbitConsumerProperties> consumerProperties = createConsumerProperties();
	RabbitTestSupport.RabbitProxy proxy = new RabbitTestSupport.RabbitProxy();
	CachingConnectionFactory cf = new CachingConnectionFactory("localhost",
			proxy.getPort());

	final RabbitExchangeQueueProvisioner rabbitExchangeQueueProvisioner = new RabbitExchangeQueueProvisioner(cf);

	consumerProperties.setMultiplex(true);
	consumerProperties.setPartitioned(true);
	consumerProperties.setInstanceIndexList(Arrays.asList(1, 2, 3));

	final ConsumerDestination consumerDestination = rabbitExchangeQueueProvisioner.provisionConsumerDestination("foo", "boo", consumerProperties);

	final String name = consumerDestination.getName();

	assertThat(name).isEqualTo("foo.boo-1,foo.boo-2,foo.boo-3");
}
 
Example 2
Source File: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiplexOnPartitionedConsumerWithMultipleDestinations() throws Exception {
	final ExtendedConsumerProperties<RabbitConsumerProperties> consumerProperties = createConsumerProperties();
	RabbitTestSupport.RabbitProxy proxy = new RabbitTestSupport.RabbitProxy();
	CachingConnectionFactory cf = new CachingConnectionFactory("localhost",
			proxy.getPort());

	final RabbitExchangeQueueProvisioner rabbitExchangeQueueProvisioner = new RabbitExchangeQueueProvisioner(cf);

	consumerProperties.setMultiplex(true);
	consumerProperties.setPartitioned(true);
	consumerProperties.setInstanceIndexList(Arrays.asList(1, 2, 3));

	final ConsumerDestination consumerDestination = rabbitExchangeQueueProvisioner.provisionConsumerDestination("foo,qaa", "boo", consumerProperties);

	final String name = consumerDestination.getName();

	assertThat(name).isEqualTo("foo.boo-1,foo.boo-2,foo.boo-3,qaa.boo-1,qaa.boo-2,qaa.boo-3");
}
 
Example 3
Source File: KinesisMessageChannelBinder.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageProducer createConsumerEndpoint(ConsumerDestination destination,
		String group,
		ExtendedConsumerProperties<KinesisConsumerProperties> properties) {

	ConsumerDestination destinationToUse = destination;

	if (properties.getExtension().isDynamoDbStreams()) {
		DescribeTableResult describeTableResult = this.dynamoDBClient.describeTable(destinationToUse.getName());
		String latestStreamArn = describeTableResult.getTable().getLatestStreamArn();
		if (StringUtils.hasText(latestStreamArn)) {
			destinationToUse = new KinesisConsumerDestination(latestStreamArn, Collections.emptyList());
		}
		else {
			throw new ProvisioningException("The DynamoDB table ["
					+ destinationToUse.getName()
					+ "] doesn't have Streams enabled.");
		}
	}
	else {
		this.streamsInUse.add(destinationToUse.getName());
	}

	MessageProducer adapter;
	if (this.configurationProperties.isKplKclEnabled()) {
		adapter = createKclConsumerEndpoint(destinationToUse, group, properties);
	}
	else {
		adapter = createKinesisConsumerEndpoint(destinationToUse, group, properties);
	}

	return adapter;
}
 
Example 4
Source File: PubSubMessageChannelBinder.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group,
		ExtendedConsumerProperties<PubSubConsumerProperties> properties) {

	PubSubInboundChannelAdapter adapter = new PubSubInboundChannelAdapter(this.pubSubTemplate,
			destination.getName());

	ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, group, properties);
	adapter.setErrorChannel(errorInfrastructure.getErrorChannel());
	adapter.setAckMode(properties.getExtension().getAckMode());

	return adapter;
}
 
Example 5
Source File: RabbitMessageChannelBinder.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 5 votes vote down vote up
@Override
protected PolledConsumerResources createPolledConsumerResources(String name,
		String group, ConsumerDestination destination,
		ExtendedConsumerProperties<RabbitConsumerProperties> consumerProperties) {

	Assert.isTrue(!consumerProperties.isMultiplex(),
			"The Spring Integration polled MessageSource does not currently support muiltiple queues");
	AmqpMessageSource source = new AmqpMessageSource(this.connectionFactory,
			destination.getName());
	source.setRawMessageHeader(true);
	getMessageSourceCustomizer().configure(source, destination.getName(), group);
	return new PolledConsumerResources(source, registerErrorInfrastructure(
			destination, group, consumerProperties, true));
}
 
Example 6
Source File: RocketMQMessageChannelBinder.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@Override
protected MessageProducer createConsumerEndpoint(ConsumerDestination destination,
		String group,
		ExtendedConsumerProperties<RocketMQConsumerProperties> consumerProperties)
		throws Exception {
	if (group == null || "".equals(group)) {
		throw new RuntimeException(
				"'group must be configured for channel " + destination.getName());
	}

	RocketMQListenerBindingContainer listenerContainer = new RocketMQListenerBindingContainer(
			consumerProperties, rocketBinderConfigurationProperties, this);
	listenerContainer.setConsumerGroup(group);
	listenerContainer.setTopic(destination.getName());
	listenerContainer.setConsumeThreadMax(consumerProperties.getConcurrency());
	listenerContainer.setSuspendCurrentQueueTimeMillis(
			consumerProperties.getExtension().getSuspendCurrentQueueTimeMillis());
	listenerContainer.setDelayLevelWhenNextConsume(
			consumerProperties.getExtension().getDelayLevelWhenNextConsume());
	listenerContainer
			.setNameServer(rocketBinderConfigurationProperties.getNameServer());
	listenerContainer.setHeaderMapper(createHeaderMapper(consumerProperties));

	RocketMQInboundChannelAdapter rocketInboundChannelAdapter = new RocketMQInboundChannelAdapter(
			listenerContainer, consumerProperties, instrumentationManager);

	topicInUse.put(destination.getName(), group);

	ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination,
			group, consumerProperties);
	if (consumerProperties.getMaxAttempts() > 1) {
		rocketInboundChannelAdapter
				.setRetryTemplate(buildRetryTemplate(consumerProperties));
		rocketInboundChannelAdapter
				.setRecoveryCallback(errorInfrastructure.getRecoverer());
	}
	else {
		rocketInboundChannelAdapter
				.setErrorChannel(errorInfrastructure.getErrorChannel());
	}

	return rocketInboundChannelAdapter;
}
 
Example 7
Source File: KinesisMessageChannelBinder.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 4 votes vote down vote up
private MessageProducer createKclConsumerEndpoint(ConsumerDestination destination, String group,
		ExtendedConsumerProperties<KinesisConsumerProperties> properties) {
	KinesisConsumerProperties kinesisConsumerProperties = properties.getExtension();

	String shardIteratorType = kinesisConsumerProperties.getShardIteratorType();

	AmazonKinesis amazonKinesisClient =
			kinesisConsumerProperties.isDynamoDbStreams()
					? this.dynamoDBStreamsAdapter
					: this.amazonKinesis;

	String stream = destination.getName();

	KinesisClientLibConfiguration kinesisClientLibConfiguration = obtainKinesisClientLibConfiguration(stream, group);

	KclMessageDrivenChannelAdapter adapter;

	String consumerGroup;
	if (kinesisClientLibConfiguration == null) {
		adapter = new KclMessageDrivenChannelAdapter(stream, amazonKinesisClient, this.cloudWatchClient,
						this.dynamoDBClient, this.awsCredentialsProvider);
		boolean anonymous = !StringUtils.hasText(group);
		consumerGroup = anonymous ? "anonymous." + UUID.randomUUID().toString() : group;
		adapter.setConsumerGroup(consumerGroup);
		if (StringUtils.hasText(shardIteratorType)) {
			adapter.setStreamInitialSequence(InitialPositionInStream.valueOf(shardIteratorType));
		}
		adapter.setIdleBetweenPolls(kinesisConsumerProperties.getIdleBetweenPolls());
		adapter.setConsumerBackoff(kinesisConsumerProperties.getConsumerBackoff());
		if (kinesisConsumerProperties.getWorkerId() != null) {
			adapter.setWorkerId(kinesisConsumerProperties.getWorkerId());
		}
	}
	else {
		adapter = new KclMessageDrivenChannelAdapter(kinesisClientLibConfiguration, amazonKinesisClient,
				this.cloudWatchClient, this.dynamoDBClient);
		consumerGroup = kinesisClientLibConfiguration.getApplicationName();
	}

	adapter.setCheckpointMode(kinesisConsumerProperties.getCheckpointMode());
	adapter.setCheckpointsInterval(kinesisConsumerProperties.getCheckpointInterval());

	adapter.setListenerMode(kinesisConsumerProperties.getListenerMode());

	if (properties.isUseNativeDecoding()) {
		adapter.setConverter(null);
	}
	else {
		// Defer byte[] conversion to the InboundContentTypeConvertingInterceptor
		adapter.setConverter((bytes) -> bytes);
	}

	ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, consumerGroup, properties);
	adapter.setErrorMessageStrategy(ERROR_MESSAGE_STRATEGY);
	adapter.setErrorChannel(errorInfrastructure.getErrorChannel());
	adapter.setBindSourceRecord(true);
	return adapter;
}
 
Example 8
Source File: PubSubMessageChannelBinder.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Override
protected String errorsBaseName(
		ConsumerDestination destination, String group, ExtendedConsumerProperties<PubSubConsumerProperties> properties) {
	return destination.getName() + ".errors";
}
 
Example 9
Source File: PubSubMessageChannelBinder.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Override
protected PolledConsumerResources createPolledConsumerResources(String name, String group, ConsumerDestination destination,
		ExtendedConsumerProperties<PubSubConsumerProperties> consumerProperties) {
	return new PolledConsumerResources(new PubSubMessageSource(this.pubSubTemplate, destination.getName()),
			registerErrorInfrastructure(destination, group, consumerProperties, true));
}
 
Example 10
Source File: RabbitMessageChannelBinder.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Override
protected MessageProducer createConsumerEndpoint(
		ConsumerDestination consumerDestination, String group,
		ExtendedConsumerProperties<RabbitConsumerProperties> properties) {
	Assert.state(!HeaderMode.embeddedHeaders.equals(properties.getHeaderMode()),
			"the RabbitMQ binder does not support embedded headers since RabbitMQ supports headers natively");
	String destination = consumerDestination.getName();
	boolean directContainer = properties.getExtension().getContainerType()
			.equals(ContainerType.DIRECT);
	AbstractMessageListenerContainer listenerContainer = directContainer
			? new DirectMessageListenerContainer(this.connectionFactory)
			: new SimpleMessageListenerContainer(this.connectionFactory);
	listenerContainer
			.setAcknowledgeMode(properties.getExtension().getAcknowledgeMode());
	listenerContainer.setChannelTransacted(properties.getExtension().isTransacted());
	listenerContainer
			.setDefaultRequeueRejected(properties.getExtension().isRequeueRejected());
	int concurrency = properties.getConcurrency();
	concurrency = concurrency > 0 ? concurrency : 1;
	if (directContainer) {
		setDMLCProperties(properties,
				(DirectMessageListenerContainer) listenerContainer, concurrency);
	}
	else {
		setSMLCProperties(properties,
				(SimpleMessageListenerContainer) listenerContainer, concurrency);
	}
	listenerContainer.setPrefetchCount(properties.getExtension().getPrefetch());
	listenerContainer
			.setRecoveryInterval(properties.getExtension().getRecoveryInterval());
	listenerContainer.setTaskExecutor(
			new SimpleAsyncTaskExecutor(consumerDestination.getName() + "-"));
	String[] queues = StringUtils.tokenizeToStringArray(destination, ",", true, true);
	listenerContainer.setQueueNames(queues);
	listenerContainer.setAfterReceivePostProcessors(this.decompressingPostProcessor);
	listenerContainer.setMessagePropertiesConverter(
			RabbitMessageChannelBinder.inboundMessagePropertiesConverter);
	listenerContainer.setExclusive(properties.getExtension().isExclusive());
	listenerContainer
			.setMissingQueuesFatal(properties.getExtension().getMissingQueuesFatal());
	if (properties.getExtension().getFailedDeclarationRetryInterval() != null) {
		listenerContainer.setFailedDeclarationRetryInterval(
				properties.getExtension().getFailedDeclarationRetryInterval());
	}
	if (getApplicationEventPublisher() != null) {
		listenerContainer
				.setApplicationEventPublisher(getApplicationEventPublisher());
	}
	else if (getApplicationContext() != null) {
		listenerContainer.setApplicationEventPublisher(getApplicationContext());
	}
	getContainerCustomizer().configure(listenerContainer,
			consumerDestination.getName(), group);
	if (StringUtils.hasText(properties.getExtension().getConsumerTagPrefix())) {
		final AtomicInteger index = new AtomicInteger();
		listenerContainer.setConsumerTagStrategy(
				q -> properties.getExtension().getConsumerTagPrefix() + "#"
						+ index.getAndIncrement());
	}
	listenerContainer.afterPropertiesSet();

	AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(
			listenerContainer);
	adapter.setBindSourceMessage(true);
	adapter.setBeanFactory(this.getBeanFactory());
	adapter.setBeanName("inbound." + destination);
	DefaultAmqpHeaderMapper mapper = DefaultAmqpHeaderMapper.inboundMapper();
	mapper.setRequestHeaderNames(properties.getExtension().getHeaderPatterns());
	adapter.setHeaderMapper(mapper);
	ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(
			consumerDestination, group, properties);
	if (properties.getMaxAttempts() > 1) {
		adapter.setRetryTemplate(buildRetryTemplate(properties));
		adapter.setRecoveryCallback(errorInfrastructure.getRecoverer());
	}
	else {
		adapter.setErrorMessageStrategy(errorMessageStrategy);
		adapter.setErrorChannel(errorInfrastructure.getErrorChannel());
	}
	adapter.setMessageConverter(passThoughConverter);
	return adapter;
}
 
Example 11
Source File: RabbitMessageChannelBinder.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Override
protected String errorsBaseName(ConsumerDestination destination, String group,
		ExtendedConsumerProperties<RabbitConsumerProperties> consumerProperties) {
	return destination.getName() + ".errors";
}
 
Example 12
Source File: AbstractMessageChannelBinder.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
protected String errorsBaseName(ConsumerDestination destination, String group,
		C consumerProperties) {
	return destination.getName() + "." + group + ".errors";
}