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


Java RabbitAdmin.declareBinding方法代码示例

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


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

示例1: checkRabbitMQAMQPProtocol

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的package包/类
public String checkRabbitMQAMQPProtocol(String messageAsString,
                                        String url,
                                        String user,
                                        String password,
                                        String vhost) throws Exception {
    org.springframework.amqp.rabbit.connection.CachingConnectionFactory cf =
            new org.springframework.amqp.rabbit.connection.CachingConnectionFactory();
    URL formattedUrl = new URL("http://" + url);
    cf.setHost(formattedUrl.getHost());
    cf.setPort(formattedUrl.getPort());
    cf.setUsername(user);
    cf.setPassword(password);
    cf.setVirtualHost(vhost);
    RabbitAdmin admin = new RabbitAdmin(cf);
    org.springframework.amqp.core.Queue queue = new org.springframework.amqp.core.Queue("myQueue");
    admin.declareQueue(queue);
    TopicExchange exchange = new TopicExchange("myExchange");
    admin.declareExchange(exchange);
    admin.declareBinding(
            BindingBuilder.bind(queue).to(exchange).with("foo.*"));
    RabbitTemplate template = new RabbitTemplate(cf);
    template.convertAndSend("myExchange", "foo.bar", messageAsString);
    String receivedMessage = template.receiveAndConvert("myQueue").toString();
    return receivedMessage;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:26,代码来源:CheckBrokerConnectionUtils.java

示例2: afterPropertiesSet

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
	List<RabbitAdmin> rabbitAdmins = getMqAdmins();
	for (int i = 0; i < rabbitAdmins.size(); i++) {
		RabbitAdmin rabbitAdmin = rabbitAdmins.get(i);
		while (true) {
			if (!DEFAULT_EXCHANGE.equals(exchange)) {
				break;
			}
			try {
				rabbitAdmin.declareQueue(new Queue(routingKey, queueDurable, queueExclusive, queueAutoDelete, queueArguments));
				rabbitAdmin.declareBinding(new Binding(routingKey, DestinationType.QUEUE, MQClient.DEFAULT_EXCHANGE, routingKey, bindingArguments));
				break;
			} catch (Exception e) {
				LogUtil.warn(logger, "�������У�" + routingKey + "��ʧ��", e);
			}
		}
	}
}
 
开发者ID:xiaolongzuo,项目名称:zxl,代码行数:20,代码来源:MQClient.java

示例3: rabbitAdmin

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的package包/类
@Bean
@Required
RabbitAdmin rabbitAdmin(String uniqueQueueName) {
  RabbitAdmin admin = new RabbitAdmin(connectionFactory());
  admin.setAutoStartup(true);
  admin.declareExchange(eventBusExchange());
  admin.declareQueue(eventStream(uniqueQueueName));
  admin.declareBinding(binding(uniqueQueueName));
  return admin;
}
 
开发者ID:drm317,项目名称:cloud-native-reference,代码行数:11,代码来源:RabbitConfiguration.java

示例4: rabbitAdmin

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的package包/类
@Bean
@Required
RabbitAdmin rabbitAdmin() {
  RabbitAdmin admin = new RabbitAdmin(connectionFactory());
  admin.setAutoStartup(true);
  admin.declareExchange(eventBusExchange());
  admin.declareQueue(defaultStream());
  admin.declareBinding(binding());
  return admin;
}
 
开发者ID:drm317,项目名称:cloud-native-reference,代码行数:11,代码来源:RabbitConfiguration.java

示例5: testConsumerPropertiesWithUserInfrastructureNoBind

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的package包/类
@Test
public void testConsumerPropertiesWithUserInfrastructureNoBind() throws Exception {
	RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource());
	Queue queue = new Queue("propsUser1.infra");
	admin.declareQueue(queue);
	DirectExchange exchange = new DirectExchange("propsUser1");
	admin.declareExchange(exchange);
	admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo"));

	RabbitTestBinder binder = getBinder();
	ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties();
	properties.getExtension().setDeclareExchange(false);
	properties.getExtension().setBindQueue(false);

	Binding<MessageChannel> consumerBinding = binder.bindConsumer("propsUser1", "infra",
			createBindableChannel("input", new BindingProperties()), properties);
	Lifecycle endpoint = extractEndpoint(consumerBinding);
	SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
			SimpleMessageListenerContainer.class);
	assertThat(TestUtils.getPropertyValue(container, "missingQueuesFatal", Boolean.class)).isFalse();
	assertThat(container.isRunning()).isTrue();
	consumerBinding.unbind();
	assertThat(container.isRunning()).isFalse();
	RabbitManagementTemplate rmt = new RabbitManagementTemplate();
	List<org.springframework.amqp.core.Binding> bindings = rmt.getBindingsForExchange("/", exchange.getName());
	assertThat(bindings.size()).isEqualTo(1);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-rabbit,代码行数:28,代码来源:RabbitBinderTests.java

示例6: testRoutingKeyExpression

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的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

示例7: rabbitAdmin

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的package包/类
@Bean
@Required
RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory, FanoutExchange fanoutExchange, Queue eventStream, Binding binding) {
    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    admin.setAutoStartup(true);
    admin.declareExchange(fanoutExchange);
    admin.declareQueue(eventStream);
    admin.declareBinding(binding);
    return admin;
}
 
开发者ID:benwilcock,项目名称:cf-cqrs-microservice-sampler,代码行数:11,代码来源:AxonConfiguration.java

示例8: init

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的package包/类
@PostConstruct
private void init() throws IOException {
  log.info("Initialization of VnfmSpringHelperRabbit");
  rabbitAdmin = new RabbitAdmin(connectionFactory);
  rabbitAdmin.declareExchange(new TopicExchange("openbaton-exchange"));
  rabbitAdmin.declareQueue(
      new Queue(RabbitConfiguration.queueName_vnfmRegister, true, exclusive, autodelete));
  rabbitAdmin.declareBinding(
      new Binding(
          RabbitConfiguration.queueName_vnfmRegister,
          Binding.DestinationType.QUEUE,
          "openbaton-exchange",
          RabbitConfiguration.queueName_vnfmRegister,
          null));
}
 
开发者ID:openbaton,项目名称:openbaton-libs,代码行数:16,代码来源:VnfmSpringHelperRabbit.java

示例9: handleReceiveError

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的package包/类
protected void handleReceiveError(Exception warnException, RabbitAdmin mqAdmin) {
	Throwable throwable = warnException;
	while ((throwable = throwable.getCause()) != null) {
		if (throwable instanceof ShutdownSignalException && throwable.getMessage().contains(NOT_FOUND_MESSAGE)) {
			try {
				mqAdmin.declareQueue(new Queue(queueName, queueDurable, queueExclusive, queueAutoDelete, queueArguments));
				mqAdmin.declareBinding(new Binding(queueName, DestinationType.QUEUE, MQClient.DEFAULT_EXCHANGE, queueName, bindingArguments));
			} catch (Exception e) {
			}
			break;
		}
	}
}
 
开发者ID:xiaolongzuo,项目名称:zxl,代码行数:14,代码来源:MQServer.java

示例10: testRoutingKeyExpressionPartitionedAndDelay

import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入方法依赖的package包/类
@Test
	public void testRoutingKeyExpressionPartitionedAndDelay() throws Exception {
		RabbitTestBinder binder = getBinder();
		ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
		producerProperties.getExtension().setRoutingKeyExpression("payload.field");
		// requires delayed message exchange plugin; tested locally
//		producerProperties.getExtension().setDelayedExchange(true);
		producerProperties.getExtension().setDelayExpression("1000");
		producerProperties.setPartitionKeyExpression(new ValueExpression<>(0));

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

		RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource());
		Queue queue = new AnonymousQueue();
		TopicExchange exchange = new TopicExchange("rkep");
		org.springframework.amqp.core.Binding binding =
				BindingBuilder.bind(queue).to(exchange).with("rkepTest-0");
		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("rkepTest");
				assertThat(message.getHeaders().get(RabbitExpressionEvaluatingInterceptor.DELAY_HEADER))
					.isEqualTo(1000);
				return message;
			}

		});

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

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

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


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