當前位置: 首頁>>代碼示例>>Java>>正文


Java RabbitAdmin.declareQueue方法代碼示例

本文整理匯總了Java中org.springframework.amqp.rabbit.core.RabbitAdmin.declareQueue方法的典型用法代碼示例。如果您正苦於以下問題:Java RabbitAdmin.declareQueue方法的具體用法?Java RabbitAdmin.declareQueue怎麽用?Java RabbitAdmin.declareQueue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.amqp.rabbit.core.RabbitAdmin的用法示例。


在下文中一共展示了RabbitAdmin.declareQueue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: declareQueue

import org.springframework.amqp.rabbit.core.RabbitAdmin; //導入方法依賴的package包/類
@Override
public void declareQueue() throws IOException {

    RabbitAdmin rabbitAdmin = rabbitAdmin();

    try {
        rabbitAdmin.declareQueue(new Queue("demo2",false,false,false));
    }catch (Exception e){
        try {
            if (406 == ((AMQImpl.Channel.Close) ((ShutdownSignalException)e.getCause().getCause()).getReason()).getReplyCode()) {
                rabbitAdmin.deleteQueue("demo2");
                declareQueue();
            }
        }catch (Exception e1){
        }
        log.error("e 's value : {}", e);
    }


}
 
開發者ID:laidu,項目名稱:java-learn,代碼行數:21,代碼來源:SpringClientDemo.java

示例3: init

import org.springframework.amqp.rabbit.core.RabbitAdmin; //導入方法依賴的package包/類
@PostConstruct
private void init() {
  log.info("Initialization of RabbitConfiguration");

  emsConnectionFactory = new CachingConnectionFactory();
  ((CachingConnectionFactory) emsConnectionFactory).setHost(brokerIp);
  ((CachingConnectionFactory) emsConnectionFactory).setPort(rabbitPort);
  ((CachingConnectionFactory) emsConnectionFactory).setUsername(emsRabbitUsername);
  ((CachingConnectionFactory) emsConnectionFactory).setPassword(emsRabbitPassword);

  rabbitAdmin = new RabbitAdmin(emsConnectionFactory);
  TopicExchange topicExchange = new TopicExchange("openbaton-exchange");
  rabbitAdmin.declareExchange(topicExchange);
  log.info("exchange declared");

  queueName_emsRegistrator = "ems." + vnfmHelper.getVnfmEndpoint() + ".register";
  rabbitAdmin.declareQueue(new Queue(queueName_emsRegistrator, durable, exclusive, autodelete));
}
 
開發者ID:openbaton,項目名稱:generic-vnfm,代碼行數:19,代碼來源:EMSConfiguration.java

示例4: declareExchange

import org.springframework.amqp.rabbit.core.RabbitAdmin; //導入方法依賴的package包/類
@Test
public void declareExchange() throws Exception {
	RabbitAdmin bean = (RabbitAdmin) applicationContext
			.getBean("rabbitAdmin");
	//
	String EXCHANGE_NAME = "TEST_EXCHANGE";
	TopicExchange exchange = new TopicExchange(EXCHANGE_NAME);
	bean.declareExchange(exchange);
	//
	String QUEUE_NAME = "TEST_EXCHANGE";
	Queue queue = new Queue(QUEUE_NAME, false);
	bean.declareQueue(queue);
	//
	// binding
	Binding binding = BindingBuilder.bind(queue).to(exchange)
			.with(QUEUE_NAME);
	System.out.println(binding);
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:19,代碼來源:ApplicationContextRabbitmqTest.java

示例5: 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

示例6: 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

示例7: 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

示例8: zhihuUserDataQueue

import org.springframework.amqp.rabbit.core.RabbitAdmin; //導入方法依賴的package包/類
/**
 * 配置知乎用戶資料隊列 bean
 * 
 * @param rabbitAdmin
 * @return
 */
@Bean
public Queue zhihuUserDataQueue(@Autowired RabbitAdmin rabbitAdmin) {

	// 創建知乎用戶資料隊列對象
	Queue ubdQueue = new Queue("zhuhu.user.queue");

	// 聲明知乎用戶資料隊列
	rabbitAdmin.declareQueue(ubdQueue);

	// 返回知乎用戶資料隊列
	return ubdQueue;
}
 
開發者ID:sdc1234,項目名稱:zhihu-spider,代碼行數:19,代碼來源:RabbitmqConfiguration.java

示例9: userBehaviorDataQueue

import org.springframework.amqp.rabbit.core.RabbitAdmin; //導入方法依賴的package包/類
/**
 * 配置知乎問題隊列 bean
 * 
 * @param rabbitAdmin
 * @return
 */
@Bean
public Queue userBehaviorDataQueue(@Autowired RabbitAdmin rabbitAdmin) {

	// 創建知乎問題隊列對象
	Queue ubdQueue = new Queue("zhuhu.question.queue");

	// 聲明知乎問題隊列
	rabbitAdmin.declareQueue(ubdQueue);

	// 返回知乎問題隊列
	return ubdQueue;
}
 
開發者ID:sdc1234,項目名稱:zhihu-spider,代碼行數:19,代碼來源:RabbitmqConfiguration.java

示例10: testConnect

import org.springframework.amqp.rabbit.core.RabbitAdmin; //導入方法依賴的package包/類
@Test
public void testConnect() {
	RabbitAdmin admin = new RabbitAdmin(this.lqcf);
	Queue queue = new Queue(UUID.randomUUID().toString(), false, false, true);
	admin.declareQueue(queue);
	ConnectionFactory targetConnectionFactory = this.lqcf.getTargetConnectionFactory("[" + queue.getName() + "]");
	RabbitTemplate template = new RabbitTemplate(targetConnectionFactory);
	template.convertAndSend("", queue.getName(), "foo");
	assertThat(template.receiveAndConvert(queue.getName())).isEqualTo("foo");
	((CachingConnectionFactory) targetConnectionFactory).destroy();
	admin.deleteQueue(queue.getName());
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-rabbit,代碼行數:13,代碼來源:LocalizedQueueConnectionFactoryIntegrationTests.java

示例11: 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

示例12: testBadUserDeclarationsFatal

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

示例13: 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

示例14: 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

示例15: 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


注:本文中的org.springframework.amqp.rabbit.core.RabbitAdmin.declareQueue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。