org.springframework.amqp.core.TopicExchange Java Examples

The following examples show how to use org.springframework.amqp.core.TopicExchange. 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: EMSConfiguration.java    From generic-vnfm with 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 #2
Source File: RabbitWithoutRabbitTemplateConfig.java    From java-spring-rabbitmq with Apache License 2.0 6 votes vote down vote up
@Bean
public RabbitAdmin rabbitAdmin(Queue queue, ConnectionFactory connectionFactory) {
  final TopicExchange exchange = new TopicExchange("myExchange", true, false);

  final RabbitAdmin admin = new RabbitAdmin(connectionFactory);
  admin.declareQueue(queue);
  admin.declareExchange(exchange);
  admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("#"));

  return admin;
}
 
Example #3
Source File: SpringIntegrationTest.java    From rabbitmq-mock with 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 #4
Source File: MessageConsumerConfiguration.java    From code-examples with MIT License 5 votes vote down vote up
@Bean
public Binding binding(Queue eventReceivingQueue, TopicExchange receiverExchange) {
	return BindingBuilder
					.bind(eventReceivingQueue)
					.to(receiverExchange)
					.with("*.*");
}
 
Example #5
Source File: CoreRabbitMQConfiguration.java    From abixen-platform with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Bean
List<Binding> binding(TopicExchange exchange) {
    List<Binding> bindings = new ArrayList<>();

    queues().forEach(queue -> {
        bindings.add(BindingBuilder.bind(queue).to(exchange).with(queue.getName()));
    });

    return bindings;
}
 
Example #6
Source File: EventSubscriberConfiguration.java    From code-examples with MIT License 5 votes vote down vote up
@Bean
public Binding binding(Queue eventReceivingQueue, TopicExchange receiverExchange) {
  if (routingKey == null) {
    throw new IllegalStateException("No events to listen to! Please specify the routing key for the events to listen to with the property 'subscriber.routingKey' (see EventPublisher for available routing keys).");
  }
  return BindingBuilder
          .bind(eventReceivingQueue)
          .to(receiverExchange)
          .with(routingKey);
}
 
Example #7
Source File: EventSubscriberConfiguration.java    From articles with Apache License 2.0 5 votes vote down vote up
@Bean
public Binding binding(Queue eventReceivingQueue, TopicExchange receiverExchange) {
    if (routingKey == null) {
        throw new IllegalStateException("No events to listen to! Please specify the routing key for the events to listen to with the property 'subscriber.routingKey' (see EventPublisher for available routing keys).");
    }
    return BindingBuilder
            .bind(eventReceivingQueue)
            .to(receiverExchange)
            .with(routingKey);
}
 
Example #8
Source File: Configurations.java    From Hands-On-RESTful-API-Design-Patterns-and-Best-Practices with MIT License 5 votes vote down vote up
private List<TopicExchange> serviceExchanges() {
	return rabbitMqConfig.getServiceRoutings().stream().map(rabbitMqConfig::getExchangeName).map(e -> {
		TopicExchange exchange = new TopicExchange(e);
		exchanegMap.put(e, exchange);
		return exchange;
	}).collect(Collectors.toList());
}
 
Example #9
Source File: Configurations.java    From Hands-On-RESTful-API-Design-Patterns-and-Best-Practices with MIT License 5 votes vote down vote up
private List<TopicExchange> eventExchanges() {
	return rabbitMqConfig.getEventRoutings().stream().map(rabbitMqConfig::getExchangeName).map(e -> {
		TopicExchange exchange = new TopicExchange(e);
		exchanegMap.put(e, exchange);
		return exchange;
	}).collect(Collectors.toList());
}
 
Example #10
Source File: Issue178ListenerConfiguration.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Bean
TopicExchange issue178InputExchange() {
	return new TopicExchange("rated-item-service.rated-item-event.exchange");
}
 
Example #11
Source File: MessageProviderConfiguration.java    From code-examples with MIT License 4 votes vote down vote up
@Bean
TopicExchange topicExchange() {
	return new TopicExchange("myExchange");
}
 
Example #12
Source File: MessageProviderConfiguration.java    From code-examples with MIT License 4 votes vote down vote up
@Bean
MessagePublisher messagePublisher(RabbitTemplate rabbitTemplate, TopicExchange topicExchange) {
	return new MessagePublisher(rabbitTemplate, topicExchange);
}
 
Example #13
Source File: RabbitChannelDefinitionProcessorTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@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 #14
Source File: RabbitConfig.java    From POC with Apache License 2.0 4 votes vote down vote up
@Bean
Binding binding(Queue ordersQueue, TopicExchange ordersExchange) {
	return BindingBuilder.bind(ordersQueue).to(ordersExchange).with(QUEUE_ORDERS);
}
 
Example #15
Source File: Issue178ListenerConfiguration.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Bean
TopicExchange issue178OutputExchange() {
	return new TopicExchange("bill-service.rated-item-event.retry-exchange");
}
 
Example #16
Source File: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Test
public void testRoutingKeyExpression() throws Exception {
	RabbitTestBinder binder = getBinder();
	ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
	producerProperties.getExtension().setRoutingKeyExpression(
			spelExpressionParser.parseExpression("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 ChannelInterceptor() {

		@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();
}
 
Example #17
Source File: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Test
public void testRoutingKeyExpressionPartitionedAndDelay() throws Exception {
	RabbitTestBinder binder = getBinder();
	ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
	producerProperties.getExtension().setRoutingKeyExpression(
			spelExpressionParser.parseExpression("#root.getPayload().field"));
	// requires delayed message exchange plugin; tested locally
	// producerProperties.getExtension().setDelayedExchange(true);
	producerProperties.getExtension()
			.setDelayExpression(spelExpressionParser.parseExpression("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 ChannelInterceptor() {

		@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();
}
 
Example #18
Source File: Application.java    From journeyFromMonolithToMicroservices with MIT License 4 votes vote down vote up
@Bean
TopicExchange exchange() {
    return new TopicExchange("spring-boot-exchange");
}
 
Example #19
Source File: MQConsumerConfig.java    From lemon-rabbitmq with Apache License 2.0 4 votes vote down vote up
@Bean
public Binding binding(Queue queue, TopicExchange exchange){
    return BindingBuilder.bind(queue).to(exchange).with(routingkey);
}
 
Example #20
Source File: MessageConsumerConfiguration.java    From code-examples with MIT License 4 votes vote down vote up
@Bean
public TopicExchange receiverExchange() {
	return new TopicExchange(EXCHANGE_NAME);
}
 
Example #21
Source File: EventPublisher.java    From code-examples with MIT License 4 votes vote down vote up
@Autowired
public EventPublisher(RabbitTemplate rabbitTemplate, TopicExchange topicExchange) {
  this.rabbitTemplate = rabbitTemplate;
  this.topicExchange = topicExchange;
}
 
Example #22
Source File: EventSubscriberConfiguration.java    From code-examples with MIT License 4 votes vote down vote up
@Bean
public TopicExchange receiverExchange() {
  return new TopicExchange("eventExchange");
}
 
Example #23
Source File: EventPublisherConfiguration.java    From code-examples with MIT License 4 votes vote down vote up
@Bean
public EventPublisher eventPublisher(RabbitTemplate rabbitTemplate, TopicExchange senderTopicExchange) {
  return new EventPublisher(rabbitTemplate, senderTopicExchange);
}
 
Example #24
Source File: EventPublisherConfiguration.java    From code-examples with MIT License 4 votes vote down vote up
@Bean
public TopicExchange senderTopicExchange() {
  return new TopicExchange("eventExchange");
}
 
Example #25
Source File: EventPublisher.java    From articles with Apache License 2.0 4 votes vote down vote up
@Autowired
public EventPublisher(RabbitTemplate rabbitTemplate, TopicExchange topicExchange) {
    this.rabbitTemplate = rabbitTemplate;
    this.topicExchange = topicExchange;
}
 
Example #26
Source File: EventSubscriberConfiguration.java    From articles with Apache License 2.0 4 votes vote down vote up
@Bean
public TopicExchange receiverExchange() {
    return new TopicExchange("eventExchange");
}
 
Example #27
Source File: EventPublisherConfiguration.java    From articles with Apache License 2.0 4 votes vote down vote up
@Bean
public EventPublisher eventPublisher(RabbitTemplate rabbitTemplate, TopicExchange senderTopicExchange) {
    return new EventPublisher(rabbitTemplate, senderTopicExchange);
}
 
Example #28
Source File: EventPublisherConfiguration.java    From articles with Apache License 2.0 4 votes vote down vote up
@Bean
public TopicExchange senderTopicExchange() {
    return new TopicExchange("eventExchange");
}
 
Example #29
Source File: RabbitMQConfiguration.java    From Spring-5.0-By-Example with MIT License 4 votes vote down vote up
@Bean
public TopicExchange emailExchange() {
  return new TopicExchange("email", true, false);
}
 
Example #30
Source File: RabbitmqConfig.java    From poseidon with Apache License 2.0 4 votes vote down vote up
@Bean
public TopicExchange itemExchange(
		@Value("${item.exchange}") final String exchangeName) {

	return new TopicExchange(exchangeName);
}