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


Java Binding.unbind方法代码示例

本文整理汇总了Java中org.springframework.cloud.stream.binder.Binding.unbind方法的典型用法代码示例。如果您正苦于以下问题:Java Binding.unbind方法的具体用法?Java Binding.unbind怎么用?Java Binding.unbind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.cloud.stream.binder.Binding的用法示例。


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

示例1: testPartitionCountIncreasedIfAutoAddPartitionsSet

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
@Ignore("Kinesalite doesn't support updateShardCount. Test only against real AWS Kinesis")
public void testPartitionCountIncreasedIfAutoAddPartitionsSet() {
	KinesisBinderConfigurationProperties configurationProperties = new KinesisBinderConfigurationProperties();

	String stream = "existing" + System.currentTimeMillis();

	AmazonKinesisAsync amazonKinesis = localKinesisResource.getResource();
	amazonKinesis.createStream(stream, 1);

	List<Shard> shards = describeStream(stream);

	assertThat(shards.size()).isEqualTo(1);

	configurationProperties.setMinShardCount(6);
	configurationProperties.setAutoAddShards(true);
	KinesisTestBinder binder = getBinder(configurationProperties);

	ExtendedConsumerProperties<KinesisConsumerProperties> consumerProperties = createConsumerProperties();
	Binding<?> binding = binder.bindConsumer(stream, "test", new NullChannel(), consumerProperties);
	binding.unbind();

	shards = describeStream(stream);

	assertThat(shards.size()).isEqualTo(6);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-aws-kinesis,代码行数:27,代码来源:KinesisBinderTests.java

示例2: testRetryFail

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
public void testRetryFail() {
	RedisTestBinder binder = getBinder();
	DirectChannel channel = new DirectChannel();
	binder.bindProducer("retry.0", channel, createProducerProperties());
	ConsumerProperties consumerProperties = new ConsumerProperties();
	consumerProperties.setMaxAttempts(2);
	consumerProperties.setBackOffInitialInterval(100);
	consumerProperties.setBackOffMultiplier(1.0);
	Binding<MessageChannel> consumerBinding = binder.bindConsumer("retry.0", "test", new DirectChannel(), consumerProperties); // no subscriber
	channel.send(new GenericMessage<>("foo"));
	RedisTemplate<String, Object> template = createTemplate();
	Object rightPop = template.boundListOps("ERRORS:retry.0.test").rightPop(5, TimeUnit.SECONDS);
	assertNotNull(rightPop);
	assertThat(new String((byte[]) rightPop), containsString("foo"));
	consumerBinding.unbind();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:18,代码来源:RedisBinderTests.java

示例3: testPartitionCountNotReduced

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPartitionCountNotReduced() throws Throwable {
	String testTopicName = "existing" + System.currentTimeMillis();

	KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();

	invokeCreateTopic(testTopicName, 6, 1);
	configurationProperties.setAutoAddPartitions(true);
	Binder binder = getBinder(configurationProperties);
	GenericApplicationContext context = new GenericApplicationContext();
	context.refresh();

	ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
	DirectChannel input = createBindableChannel("input", createConsumerBindingProperties(consumerProperties));

	Binding<?> binding = binder.bindConsumer(testTopicName, "test", input, consumerProperties);
	binding.unbind();

	assertThat(partitionSize(testTopicName)).isEqualTo(6);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:22,代码来源:KafkaBinderTests.java

示例4: testAutoConfigureTopicsDisabledSucceedsIfTopicExisting

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testAutoConfigureTopicsDisabledSucceedsIfTopicExisting() throws Throwable {
	KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();

	String testTopicName = "existing" + System.currentTimeMillis();
	invokeCreateTopic(testTopicName, 5, 1);
	configurationProperties.setAutoCreateTopics(false);
	Binder binder = getBinder(configurationProperties);

	ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();

	DirectChannel input = createBindableChannel("input", createConsumerBindingProperties(consumerProperties));
	Binding<MessageChannel> binding = binder.bindConsumer(testTopicName, "test", input, consumerProperties);
	binding.unbind();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:17,代码来源:KafkaBinderTests.java

示例5: testAutoCreateStreamForNonExistingStream

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
public void testAutoCreateStreamForNonExistingStream() throws Exception {
	KinesisTestBinder binder = getBinder();
	DirectChannel output = createBindableChannel("output", new BindingProperties());
	ExtendedConsumerProperties<KinesisConsumerProperties> consumerProperties = createConsumerProperties();
	Date testDate = new Date();
	consumerProperties.getExtension()
			.setShardIteratorType(ShardIteratorType.AT_TIMESTAMP.name() + ":" + testDate.getTime());
	String testStreamName = "nonexisting" + System.currentTimeMillis();
	Binding<?> binding = binder.bindConsumer(testStreamName, "test", output, consumerProperties);
	binding.unbind();

	DescribeStreamResult streamResult = localKinesisResource.getResource().describeStream(testStreamName);
	String createdStreamName = streamResult.getStreamDescription().getStreamName();
	int createdShards = streamResult.getStreamDescription().getShards().size();
	String createdStreamStatus = streamResult.getStreamDescription().getStreamStatus();

	assertThat(createdStreamName).isEqualTo(testStreamName);
	assertThat(createdShards)
			.isEqualTo(consumerProperties.getInstanceCount() * consumerProperties.getConcurrency());
	assertThat(createdStreamStatus).isEqualTo(StreamStatus.ACTIVE.toString());

	KinesisShardOffset shardOffset =
			TestUtils.getPropertyValue(binding, "lifecycle.streamInitialSequence", KinesisShardOffset.class);
	assertThat(shardOffset.getIteratorType()).isEqualTo(ShardIteratorType.AT_TIMESTAMP);
	assertThat(shardOffset.getTimestamp()).isEqualTo(testDate);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-aws-kinesis,代码行数:28,代码来源:KinesisBinderTests.java

示例6: testConsumerProperties

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
public void testConsumerProperties() throws Exception {
	RedisTestBinder binder = getBinder();
	ConsumerProperties properties1 = new ConsumerProperties();
	properties1.setMaxAttempts(1);
	Binding<MessageChannel> binding = binder.bindConsumer("props.0", "test", new DirectChannel(), properties1);
	AbstractEndpoint endpoint = extractEndpoint(binding);
	assertThat(endpoint, instanceOf(RedisQueueMessageDrivenEndpoint.class));
	assertSame(DirectChannel.class, TestUtils.getPropertyValue(endpoint, "outputChannel").getClass());
	binding.unbind();
	assertFalse(endpoint.isRunning());

	ConsumerProperties properties2 = new ConsumerProperties();
	properties2.setBackOffInitialInterval(2000);
	properties2.setBackOffMaxInterval(20000);
	properties2.setBackOffMultiplier(5.0);
	properties2.setConcurrency(2);
	properties2.setMaxAttempts(23);
	properties2.setInstanceIndex(0);

	binding = binder.bindConsumer("props.0", "test", new DirectChannel(), properties2);
	endpoint = extractEndpoint(binding);
	verifyConsumer(endpoint);

	binding.unbind();
	assertFalse(endpoint.isRunning());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:28,代码来源:RedisBinderTests.java

示例7: testManualAckIsNotPossibleWhenAutoCommitOffsetIsEnabledOnTheBinder

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testManualAckIsNotPossibleWhenAutoCommitOffsetIsEnabledOnTheBinder() throws Exception {
	Binder binder = getBinder();

	DirectChannel moduleOutputChannel = createBindableChannel("output",
			createProducerBindingProperties(createProducerProperties()));
	QueueChannel moduleInputChannel = new QueueChannel();

	Binding<MessageChannel> producerBinding = binder.bindProducer(
			"testManualAckIsNotPossibleWhenAutoCommitOffsetIsEnabledOnTheBinder", moduleOutputChannel,
			createProducerProperties());

	ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();

	Binding<MessageChannel> consumerBinding = binder.bindConsumer(
			"testManualAckIsNotPossibleWhenAutoCommitOffsetIsEnabledOnTheBinder", "test", moduleInputChannel,
			consumerProperties);

	String testPayload1 = "foo" + UUID.randomUUID().toString();
	Message<?> message1 = org.springframework.integration.support.MessageBuilder.withPayload(
			testPayload1.getBytes()).build();

	// Let the consumer actually bind to the producer before sending a msg
	binderBindUnbindLatency();
	moduleOutputChannel.send(message1);

	Message<?> receivedMessage = receive(moduleInputChannel);
	assertThat(receivedMessage).isNotNull();
	assertThat(receivedMessage.getHeaders().get(KafkaHeaders.ACKNOWLEDGMENT)).isNull();

	producerBinding.unbind();
	consumerBinding.unbind();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:35,代码来源:KafkaBinderTests.java

示例8: testAutoAddPartitionsDisabledSucceedsIfTopicPartitionedCorrectly

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testAutoAddPartitionsDisabledSucceedsIfTopicPartitionedCorrectly() throws Throwable {
	Binding<?> binding = null;
	try {
		KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();

		String testTopicName = "existing" + System.currentTimeMillis();
		invokeCreateTopic(testTopicName, 6, 1);
		configurationProperties.setAutoAddPartitions(false);
		Binder binder = getBinder(configurationProperties);
		ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();

		DirectChannel input = createBindableChannel("input", createConsumerBindingProperties(consumerProperties));

		// this consumer must consume from partition 2
		consumerProperties.setInstanceCount(3);
		consumerProperties.setInstanceIndex(2);
		consumerProperties.getExtension().setAutoRebalanceEnabled(false);

		binding = binder.bindConsumer(testTopicName, "test-x", input, consumerProperties);

		TopicPartitionInitialOffset[] listenedPartitions = TestUtils.getPropertyValue(binding,
				"lifecycle.messageListenerContainer.containerProperties.topicPartitions",
				TopicPartitionInitialOffset[].class);
		assertThat(listenedPartitions).hasSize(2);
		assertThat(listenedPartitions).contains(new TopicPartitionInitialOffset(testTopicName, 2),
				new TopicPartitionInitialOffset(testTopicName, 5));
		int partitions = invokePartitionSize(testTopicName);
		assertThat(partitions).isEqualTo(6);
	}
	finally {
		if (binding != null) {
			binding.unbind();
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:38,代码来源:KafkaBinderTests.java

示例9: testBadUserDeclarationsFatal

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
public void testBadUserDeclarationsFatal() throws Exception {
	RabbitTestBinder binder = getBinder();
	ConfigurableApplicationContext context = binder.getApplicationContext();
	ConfigurableListableBeanFactory bf = context.getBeanFactory();
	bf.registerSingleton("testBadUserDeclarationsFatal", new Queue("testBadUserDeclarationsFatal", false));
	bf.registerSingleton("binder", binder);
	RabbitExchangeQueueProvisioner provisioner = TestUtils.getPropertyValue(binder, "binder.provisioningProvider",
			RabbitExchangeQueueProvisioner.class);
	bf.initializeBean(provisioner, "provisioner");
	bf.registerSingleton("provisioner", provisioner);
	context.addApplicationListener(provisioner);
	RabbitAdmin admin = new RabbitAdmin(rabbitAvailableRule.getResource());
	admin.declareQueue(new Queue("testBadUserDeclarationsFatal"));
	// reset the connection and configure the "user" admin to auto declare queues...
	rabbitAvailableRule.getResource().resetConnection();
	bf.initializeBean(admin, "rabbitAdmin");
	bf.registerSingleton("rabbitAdmin", admin);
	admin.afterPropertiesSet();
	// the mis-configured queue should be fatal
	Binding<?> binding = null;
	try {
		binding = binder.bindConsumer("input", "baddecls", this.createBindableChannel("input", new BindingProperties()), createConsumerProperties());
		fail("Expected exception");
	}
	catch (BinderException e) {
		assertThat(e.getCause()).isInstanceOf(AmqpIOException.class);
	}
	finally {
		admin.deleteQueue("testBadUserDeclarationsFatal");
		if (binding != null) {
			binding.unbind();
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-rabbit,代码行数:36,代码来源:RabbitBinderTests.java

示例10: testTwoRequiredGroups

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
@Override
@SuppressWarnings("unchecked")
public void testTwoRequiredGroups() throws Exception {
	Binder binder = getBinder();
	ExtendedProducerProperties<KafkaProducerProperties> producerProperties = createProducerProperties();

	DirectChannel output = createBindableChannel("output", createProducerBindingProperties(producerProperties));

	String testDestination = "testDestination" + UUID.randomUUID().toString().replace("-", "");

	producerProperties.setRequiredGroups("test1", "test2");
	Binding<MessageChannel> producerBinding = binder.bindProducer(testDestination, output, producerProperties);

	String testPayload = "foo-" + UUID.randomUUID().toString();
	output.send(new GenericMessage<>(testPayload.getBytes()));

	QueueChannel inbound1 = new QueueChannel();
	ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
	consumerProperties.getExtension().setAutoRebalanceEnabled(false);
	Binding<MessageChannel> consumerBinding1 = binder.bindConsumer(testDestination, "test1", inbound1,
			consumerProperties);
	QueueChannel inbound2 = new QueueChannel();
	Binding<MessageChannel> consumerBinding2 = binder.bindConsumer(testDestination, "test2", inbound2,
			consumerProperties);

	Message<?> receivedMessage1 = receive(inbound1);
	assertThat(receivedMessage1).isNotNull();
	assertThat(new String((byte[]) receivedMessage1.getPayload(), StandardCharsets.UTF_8)).isEqualTo(testPayload);
	Message<?> receivedMessage2 = receive(inbound2);
	assertThat(receivedMessage2).isNotNull();
	assertThat(new String((byte[]) receivedMessage2.getPayload(), StandardCharsets.UTF_8)).isEqualTo(testPayload);

	consumerBinding1.unbind();
	consumerBinding2.unbind();
	producerBinding.unbind();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:38,代码来源:KafkaBinderTests.java

示例11: testRoutingKeyExpression

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
public void testRoutingKeyExpression() throws Exception {
	RabbitTestBinder binder = getBinder();
	ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
	producerProperties.getExtension().setRoutingKeyExpression("payload.field");

	DirectChannel output = createBindableChannel("output", createProducerBindingProperties(producerProperties));
	output.setBeanName("rkeProducer");
	Binding<MessageChannel> producerBinding = binder.bindProducer("rke", output, producerProperties);

	RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource());
	Queue queue = new AnonymousQueue();
	TopicExchange exchange = new TopicExchange("rke");
	org.springframework.amqp.core.Binding binding = BindingBuilder.bind(queue).to(exchange).with("rkeTest");
	admin.declareQueue(queue);
	admin.declareBinding(binding);

	output.addInterceptor(new ChannelInterceptorAdapter() {

		@Override
		public Message<?> preSend(Message<?> message, MessageChannel channel) {
			assertThat(message.getHeaders().get(RabbitExpressionEvaluatingInterceptor.ROUTING_KEY_HEADER))
				.isEqualTo("rkeTest");
			return message;
		}

	});

	output.send(new GenericMessage<>(new Pojo("rkeTest")));

	Object out = spyOn(queue.getName()).receive(false);
	assertThat(out).isInstanceOf(byte[].class);
	assertThat(new String((byte[]) out, StandardCharsets.UTF_8)).isEqualTo("{\"field\":\"rkeTest\"}");

	producerBinding.unbind();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-rabbit,代码行数:37,代码来源:RabbitBinderTests.java

示例12: unbindConsumers

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
public void unbindConsumers(String inputName) {
	List<Binding<?>> bindings = this.consumerBindings.remove(inputName);
	if (bindings != null && !CollectionUtils.isEmpty(bindings)) {
		for (Binding<?> binding : bindings) {
			binding.unbind();
		}
	}
	else if (log.isWarnEnabled()) {
		log.warn("Trying to unbind '" + inputName + "', but no binding found.");
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:12,代码来源:BindingService.java

示例13: unbindProducers

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
public void unbindProducers(String outputName) {
	Binding<?> binding = this.producerBindings.remove(outputName);
	if (binding != null) {
		binding.unbind();
	}
	else if (log.isWarnEnabled()) {
		log.warn("Trying to unbind '" + outputName + "', but no binding found.");
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:10,代码来源:BindingService.java

示例14: setDelegate

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
public synchronized void setDelegate(Binding<T> delegate) {
	if (this.unbound) {
		delegate.unbind();
	}
	else {
		this.delegate = delegate;
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:9,代码来源:BindingService.java

示例15: testPartitionedModuleJava

import org.springframework.cloud.stream.binder.Binding; //导入方法依赖的package包/类
@Test
@Override
public void testPartitionedModuleJava() throws Exception {
	KinesisTestBinder binder = getBinder();

	ExtendedConsumerProperties<KinesisConsumerProperties> consumerProperties = createConsumerProperties();
	consumerProperties.setConcurrency(2);
	consumerProperties.setInstanceCount(3);
	consumerProperties.setInstanceIndex(0);
	consumerProperties.setPartitioned(true);

	final List<Message<?>> results = new ArrayList<>();
	final CountDownLatch receiveLatch = new CountDownLatch(3);

	MessageHandler receivingHandler = message -> {
		results.add(message);
		receiveLatch.countDown();
	};

	DirectChannel input0 = createBindableChannel("test.input0J", new BindingProperties());
	input0.subscribe(receivingHandler);

	Binding<MessageChannel> input0Binding = binder.bindConsumer("partJ.0", "testPartitionedModuleJava", input0,
			consumerProperties);

	consumerProperties.setInstanceIndex(1);

	DirectChannel input1 = createBindableChannel("test.input1J", new BindingProperties());
	input1.subscribe(receivingHandler);

	Binding<MessageChannel> input1Binding = binder.bindConsumer("partJ.0", "testPartitionedModuleJava", input1,
			consumerProperties);

	consumerProperties.setInstanceIndex(2);

	DirectChannel input2 = createBindableChannel("test.input2J", new BindingProperties());
	input2.subscribe(receivingHandler);

	Binding<MessageChannel> input2Binding = binder.bindConsumer("partJ.0", "testPartitionedModuleJava", input2,
			consumerProperties);

	ExtendedProducerProperties<KinesisProducerProperties> producerProperties = createProducerProperties();
	producerProperties.setPartitionKeyExtractorClass(PartitionTestSupport.class);
	producerProperties.setPartitionSelectorClass(PartitionTestSupport.class);
	producerProperties.setPartitionCount(3);

	DirectChannel output = createBindableChannel("test.output",
			createProducerBindingProperties(producerProperties));

	Binding<MessageChannel> outputBinding = binder.bindProducer("partJ.0", output, producerProperties);
	if (usesExplicitRouting()) {
		Object endpoint = extractEndpoint(outputBinding);
		assertThat(getEndpointRouting(endpoint))
				.contains(getExpectedRoutingBaseDestination("partJ.0", "testPartitionedModuleJava")
						+ "-' + headers['" + BinderHeaders.PARTITION_HEADER + "']");
	}

	output.send(new GenericMessage<>(2));
	output.send(new GenericMessage<>(1));
	output.send(new GenericMessage<>(0));

	assertThat(receiveLatch.await(20, TimeUnit.SECONDS)).isTrue();

	assertThat(results).extracting("payload").containsExactlyInAnyOrder("0", "1", "2");

	input0Binding.unbind();
	input1Binding.unbind();
	input2Binding.unbind();
	outputBinding.unbind();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-aws-kinesis,代码行数:71,代码来源:KinesisBinderTests.java


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