Java Code Examples for org.springframework.amqp.core.Queue

The following examples show how to use org.springframework.amqp.core.Queue. These examples are extracted from open source projects. 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 Project: sinavi-jfw   Source File: MessageListenerRetryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void 回復可能例外の場合はデフォルトの指定回数リトライが実行されて回復可能例外キューに配信される() throws Exception {
    container.setQueues(ctx.getBean("retryTestQueue", Queue.class));
    container.setMessageListener(new MessageListenerAdapter(new ApplicationRecoverableExceptionTestHandler(), ctx.getBean(MessageConverter.class)));
    recoverableContainer.setQueues(ctx.getBean("recoverableExceptionQueue", Queue.class));
    recoverableContainer.setMessageListener(new MessageListenerAdapter(new RecoverableTestHandler(), ctx.getBean(MessageConverter.class)));
    container.start();
    recoverableContainer.start();
    template.convertAndSend("retry.test.exchange", "retry.test.binding", new RetryTestBean("test"));
    assertThat(retry.await(30, TimeUnit.SECONDS), is(true));
    assertThat(retry.getCount(), is(0L));
    assertThat(recover.await(3, TimeUnit.SECONDS), is(true));
    assertThat(recover.getCount(), is(0L));
    container.stop();
    recoverableContainer.stop();
}
 
Example 2
Source Project: generic-vnfm   Source File: EMSConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 3
@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();
		}
	}
}
 
Example 4
Source Project: articles   Source File: EventSubscriberConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Queue eventReceivingQueue() {
    if (queueName == null) {
        throw new IllegalStateException("No queue to listen to! Please specify the name of the queue to listen to with the property 'subscriber.queue'");
    }
    return new Queue(queueName);
}
 
Example 5
Source Project: rabbitmq-mock   Source File: SpringIntegrationTest.java    License: Apache License 2.0 5 votes vote down vote up
private RabbitTemplate queueAndExchangeSetup(BeanFactory context) {
    RabbitAdmin rabbitAdmin = context.getBean(RabbitAdmin.class);

    Queue queue = new Queue(QUEUE_NAME, false);
    rabbitAdmin.declareQueue(queue);
    TopicExchange exchange = new TopicExchange(EXCHANGE_NAME);
    rabbitAdmin.declareExchange(exchange);
    rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("test.*"));


    return context.getBean(RabbitTemplate.class);
}
 
Example 6
Source Project: konker-platform   Source File: RabbitMQConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Queue eventRoutesQueue() {
    boolean durable = true;
    boolean exclusive = false;
    boolean autoDelete = false;

    return new Queue("routed.events", durable, exclusive, autoDelete);
}
 
Example 7
private Binding declareConsumerBindings(String name, String routingKey,
		ExtendedConsumerProperties<RabbitConsumerProperties> properties,
		Exchange exchange, boolean partitioned, Queue queue) {

	if (partitioned) {
		return partitionedBinding(name, exchange, queue, routingKey, properties.getExtension(),
				properties.getInstanceIndex());
	}
	else {
		return notPartitionedBinding(exchange, queue, routingKey, properties.getExtension());
	}
}
 
Example 8
@Bean
Binding bindingExchangeToMessages(Queue queueMessages, TopicExchange exchange){
    return BindingBuilder.bind(queueMessages).to(exchange).with("topic.#");
}
 
Example 9
Source Project: piper   Source File: AmqpMessageBrokerConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
Queue controlQueue () {
  return new Queue(Queues.CONTROL,true,true,true);
}
 
Example 10
Source Project: Spring-5.0-By-Example   Source File: RabbitMQConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean("paymentResponseQueue")
public Queue paymentResponseQueue(){
  return new Queue(this.paymentResponseQueue,true);
}
 
Example 11
@Bean
public Queue queueMessages(){
    return new Queue(messages);
}
 
Example 12
Source Project: Spring-5.0-Cookbook   Source File: Sender.java    License: MIT License 4 votes vote down vote up
public Sender(RabbitTemplate rabbitTemplate, Queue candidateQueue) {
	this.rabbitTemplate = rabbitTemplate;
	this.candidateQueue = candidateQueue;
}
 
Example 13
@Bean
public Queue tasksQueue()
{
    return new Queue(this.tasksQueue);
}
 
Example 14
Source Project: Spring-Boot-Book   Source File: RabbitmqConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
Binding bindingExchangeA(Queue queueA, FanoutExchange fanoutExchanger) {
    return BindingBuilder.bind(queueA).to(fanoutExchanger);
}
 
Example 15
Source Project: iot-dc   Source File: RabbitMQConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public Queue instQueue() {
    return new Queue("rtu_inst_queue", true);
}
 
Example 16
Source Project: Spring-Boot-Book   Source File: RabbitConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public Queue regQueue() {
    return new Queue("reg_email");
}
 
Example 17
@Bean
Queue queue() {
	return new AnonymousQueue();
}
 
Example 18
@Bean
Binding binding(Queue queue, @Qualifier("input") TopicExchange exchange) {
	return BindingBuilder.bind(queue).to(exchange).with("#");
}
 
Example 19
@Test
public void デフォルト値が設定されて指定のインスタンスがDIコンテナに登録される() {
    assertThat(config.errorExchangeKey, is("error.exchange"));
    assertThat(config.exceptionBindingKey, is("#.exception.#"));
    assertThat(config.exceptionExchangeKey, is("exception.exchange"));
    assertThat(config.recoverableExceptionQueue, is("recoverable.exception.messages.queue"));
    assertThat(config.unrecoverableExceptionQueue, is("unrecoverable.exception.messages.queue"));
    assertThat(config.unrecoverableExceptionBindingKey, is("#.unrecoverable.exception.#"));
    assertThat(config.recoverableExceptionBindingKey, is("#.recoverable.exception.#"));
    assertThat(config.unknownExceptionRoutingKey, is("unknown.unrecoverable.exception.key"));
    TopicExchange error = context.getBean("errorExchange", TopicExchange.class);
    assertThat(error, is(notNullValue()));
    assertThat(error.getType(), is("topic"));
    assertThat(error.getName(), is("error.exchange"));
    TopicExchange exception = context.getBean("exceptionExchange", TopicExchange.class);
    assertThat(exception, is(notNullValue()));
    assertThat(exception.getType(), is("topic"));
    assertThat(exception.getName(), is("exception.exchange"));
    Queue recover = context.getBean("recoverableExceptionQueue", Queue.class);
    assertThat(recover, is(notNullValue()));
    assertThat(recover.getName(), is("recoverable.exception.messages.queue"));
    Queue unrecover = context.getBean("unrecoverableExceptionQueue", Queue.class);
    assertThat(unrecover, is(notNullValue()));
    assertThat(unrecover.getName(), is("unrecoverable.exception.messages.queue"));
    Binding exceptionBinding = context.getBean("exceptionBinding", Binding.class);
    assertThat(exceptionBinding, is(notNullValue()));
    assertThat(exceptionBinding.getExchange(), is("error.exchange"));
    assertThat(exceptionBinding.getDestination(), is("exception.exchange"));
    assertThat(exceptionBinding.getRoutingKey(), is("#.exception.#"));
    Binding recoverBinding = context.getBean("recoverableExceptionQueueBinding", Binding.class);
    assertThat(recoverBinding, is(notNullValue()));
    assertThat(recoverBinding.getExchange(), is("exception.exchange"));
    assertThat(recoverBinding.getDestination(), is("recoverable.exception.messages.queue"));
    assertThat(recoverBinding.getRoutingKey(), is("#.recoverable.exception.#"));
    Binding unrecoverBinding = context.getBean("unrecoverableExceptionQueueBinding", Binding.class);
    assertThat(unrecoverBinding, is(notNullValue()));
    assertThat(unrecoverBinding.getExchange(), is("exception.exchange"));
    assertThat(unrecoverBinding.getDestination(), is("unrecoverable.exception.messages.queue"));
    assertThat(unrecoverBinding.getRoutingKey(), is("#.unrecoverable.exception.#"));
    
    assertThat(config.retryCount, is(10));
    assertThat(config.backOffPeriod, is(1000L));
    assertThat(context.getBean(RetryOperations.class), is(notNullValue()));
    assertThat(context.getBean(ExceptionMessageExchanger.class), is(notNullValue()));
    assertThat(context.getBean(LoggingErrorHandler.class), is(notNullValue()));
    LoggingErrorHandler handler = context.getBean(LoggingErrorHandler.class);
    BinaryExceptionClassifier mapping = handler.getRetryableClassifier();
    assertThat(mapping, is(notNullValue()));
    assertThat(mapping.classify(new AmqpApplicationRecoverableException("")), is(true));
    assertThat(mapping.classify(new AmqpApplicationUnrecoverableException("")), is(false));
    assertThat(context.getBean(LoggingErrorHandler.class), is(notNullValue()));
    assertThat(context.getBean(Advice[].class), is(notNullValue()));
    assertThat(context.getBean(StatefulRetryOperationsInterceptor.class), is(notNullValue()));
}
 
Example 20
@Bean
public Queue updateCustomerQueue() {
    return new Queue("customer.update", true, false, false);
}
 
Example 21
@Test
void eventShouldBeSendAfterOutboundChannelDefinitionIsRegisteredWithDefinedExchange() {
    TopicExchange exchange = new TopicExchange("flowable-test");
    rabbitAdmin.declareExchange(exchange);
    Queue queue = new Queue("outbound-customer", false);
    rabbitAdmin.declareQueue(queue);
    Binding binding = BindingBuilder.bind(queue).to(exchange).with("customer");
    rabbitAdmin.declareBinding(binding);

    eventRepositoryService.createEventModelBuilder()
        .resourceName("testEvent.event")
        .key("customer")
        .correlationParameter("customer", EventPayloadTypes.STRING)
        .payload("name", EventPayloadTypes.STRING)
        .deploy();

    eventRepositoryService.createOutboundChannelModelBuilder()
        .key("outboundCustomer")
        .resourceName("outbound.channel")
        .rabbitChannelAdapter("customer")
        .exchange("flowable-test")
        .eventProcessingPipeline()
        .jsonSerializer()
        .deploy();

    ChannelModel channelModel = eventRepositoryService.getChannelModelByKey("outboundCustomer");

    Collection<EventPayloadInstance> payloadInstances = new ArrayList<>();
    payloadInstances.add(new EventPayloadInstanceImpl(new EventPayload("customer", EventPayloadTypes.STRING), "kermit"));
    payloadInstances.add(new EventPayloadInstanceImpl(new EventPayload("name", EventPayloadTypes.STRING), "Kermit the Frog"));
    EventInstance kermitEvent = new EventInstanceImpl("customer", payloadInstances);

    eventRegistry.sendEventOutbound(kermitEvent, Collections.singleton(channelModel));

    Object message = rabbitTemplate.receiveAndConvert("outbound-customer");
    assertThat(message).isNotNull();
    assertThatJson(message)
        .isEqualTo("{"
            + "  customer: 'kermit',"
            + "  name: 'Kermit the Frog'"
            + "}");

    rabbitAdmin.removeBinding(binding);
    rabbitAdmin.deleteExchange(exchange.getName());
}
 
Example 22
Source Project: tutorials   Source File: HelloWorldMessageApp.java    License: MIT License 4 votes vote down vote up
@Bean
public Queue myQueue() {
    return new Queue(MY_QUEUE_NAME, NON_DURABLE);
}
 
Example 23
@Bean
public Queue BMessage() {
    return new Queue("fanout.B");
}
 
Example 24
Source Project: java-tutorial   Source File: Tut2Config.java    License: MIT License 4 votes vote down vote up
@Bean
public Queue queue() {
    return new Queue("works-queues");
}
 
Example 25
Source Project: Spring-5.0-By-Example   Source File: RabbitMQConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
public Binding mailExchangeBinding(Queue mailQueue) {
  return BindingBuilder.bind(mailQueue).to(emailExchange()).with("*");
}
 
Example 26
Source Project: tutorials   Source File: DLXParkingLotAmqpConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
Queue messagesQueue() {
    return QueueBuilder.durable(QUEUE_MESSAGES)
      .withArgument("x-dead-letter-exchange", DLX_EXCHANGE_MESSAGES)
      .build();
}
 
Example 27
Source Project: open-cloud   Source File: MqAutoConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
public Queue accessLogsQueue() {
    Queue queue = new Queue(QueueConstants.QUEUE_ACCESS_LOGS);
    log.info("Query {} [{}]", QueueConstants.QUEUE_ACCESS_LOGS, queue);
    return queue;
}
 
Example 28
Source Project: Spring-5.0-Cookbook   Source File: RabbitMQEventConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public Queue queue() {
    return new Queue("login.packt.retrieval.msg");
}
 
Example 29
Source Project: fw-spring-cloud   Source File: RabbitMqConfig.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 注册一个名为hello的队列
 * @return
 */
@Bean
public Queue helloQueue(){
    return  new Queue("hello");
}
 
Example 30
Source Project: mall-learning   Source File: SimpleRabbitConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public Queue hello() {
	return new Queue("simple.hello");
}