org.springframework.amqp.core.ExchangeTypes Java Examples

The following examples show how to use org.springframework.amqp.core.ExchangeTypes. 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: GoodsListener.java    From leyou with Apache License 2.0 6 votes vote down vote up
/**
 * 处理insert和update的消息
 *
 * @param id
 * @throws Exception
 */
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = "leyou.create.index.queue", durable = "true"),
        exchange = @Exchange(
                value = "leyou.item.exchange",
                ignoreDeclarationExceptions = "true",
                type = ExchangeTypes.TOPIC),
        key = {"item.insert", "item.update"})
)
public void listenCreate(Long id) throws Exception {
    if (id == null) {
        return;
    }
    // 创建或更新索引
    this.searchService.createIndex(id);
}
 
Example #2
Source File: GoodsListener.java    From leyou with Apache License 2.0 6 votes vote down vote up
/**
 * 处理delete的消息
 *
 * @param id
 */
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = "leyou.delete.index.queue", durable = "true"),
        exchange = @Exchange(
                value = "leyou.item.exchange",
                ignoreDeclarationExceptions = "true",
                type = ExchangeTypes.TOPIC),
        key = "item.delete")
)
public void listenDelete(Long id) {
    if (id == null) {
        return;
    }
    // 删除索引
    this.searchService.deleteIndex(id);
}
 
Example #3
Source File: GoodsListener.java    From leyou with Apache License 2.0 5 votes vote down vote up
/**
 * 处理insert和update的消息
 *
 * @param id
 * @throws Exception
 */
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = "leyou.create.web.queue", durable = "true"),
        exchange = @Exchange(
                value = "leyou.item.exchange",
                ignoreDeclarationExceptions = "true",
                type = ExchangeTypes.TOPIC),
        key = {"item.insert", "item.update"}))
public void listenCreate(Long id) throws Exception {
    if (id == null) {
        return;
    }
    // 创建页面
    goodsHtmlService.createHtml(id);
}
 
Example #4
Source File: GoodsListener.java    From leyou with Apache License 2.0 5 votes vote down vote up
/**
 * 处理delete的消息
 *
 * @param id
 */
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = "leyou.delete.web.queue", durable = "true"),
        exchange = @Exchange(
                value = "leyou.item.exchange",
                ignoreDeclarationExceptions = "true",
                type = ExchangeTypes.TOPIC),
        key = "item.delete"))
public void listenDelete(Long id) {
    if (id == null) {
        return;
    }
    // 删除页面
    goodsHtmlService.deleteHtml(id);
}
 
Example #5
Source File: RabbitBroadcasterDBEventStoreIT.java    From eventeum with Apache License 2.0 5 votes vote down vote up
@RabbitListener(bindings = @QueueBinding(
        key = "contractEvents.*",
        value = @Queue("contractEvents"),
        exchange = @Exchange(value = "ThisIsAExchange", type = ExchangeTypes.TOPIC)
))
public void onContractEvent(EventeumMessage message) {
    if(message.getDetails() instanceof ContractEventDetails){
        onContractEventMessageReceived((ContractEventDetails) message.getDetails());
    } else if(message.getDetails() instanceof TransactionDetails){
        onTransactionMessageReceived((TransactionDetails) message.getDetails());
    }
}
 
Example #6
Source File: RabbitBroadcasterDBEventStoreIT.java    From eventeum with Apache License 2.0 5 votes vote down vote up
@RabbitListener(bindings = @QueueBinding(
        key = "transactionEvents.*",
        value = @Queue("transactionEvents"),
        exchange = @Exchange(value = "ThisIsAExchange", type = ExchangeTypes.TOPIC)
))
public void onTransactionEvent(EventeumMessage message) {
    onTransactionMessageReceived((TransactionDetails) message.getDetails());
}
 
Example #7
Source File: RabbitBroadcasterDBEventStoreIT.java    From eventeum with Apache License 2.0 5 votes vote down vote up
@RabbitListener(bindings = @QueueBinding(
        key = "blockEvents",
        value = @Queue("blockEvents"),
        exchange = @Exchange(value = "ThisIsAExchange", type = ExchangeTypes.TOPIC)
))
public void onBlockEvent(EventeumMessage message) {
    onBlockMessageReceived((BlockDetails) message.getDetails());
}
 
Example #8
Source File: BaseRabbitIntegrationTest.java    From eventeum with Apache License 2.0 5 votes vote down vote up
@RabbitListener(bindings = @QueueBinding(
        key = "thisIsRoutingKey.*",
        value = @Queue("ThisIsAEventsQueue"),
        exchange = @Exchange(value = "ThisIsAExchange", type = ExchangeTypes.TOPIC)
))
public void onEvent(EventeumMessage message) {
    if(message.getDetails() instanceof ContractEventDetails){
        getBroadcastContractEvents().add((ContractEventDetails) message.getDetails());
    }
    else if(message.getDetails() instanceof BlockDetails){
        getBroadcastBlockMessages().add((BlockDetails) message.getDetails());
    }

}
 
Example #9
Source File: RabbitBinderModuleTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtendedProperties() {
	context = new SpringApplicationBuilder(SimpleProcessor.class)
			.web(WebApplicationType.NONE).run("--server.port=0",
					"--spring.cloud.stream.rabbit.default.producer.routing-key-expression=fooRoutingKey",
					"--spring.cloud.stream.rabbit.default.consumer.exchange-type=direct",
					"--spring.cloud.stream.rabbit.bindings.output.producer.batch-size=512",
					"--spring.cloud.stream.rabbit.default.consumer.max-concurrency=4",
					"--spring.cloud.stream.rabbit.bindings.input.consumer.exchange-type=fanout");
	BinderFactory binderFactory = context.getBean(BinderFactory.class);
	Binder<?, ?, ?> rabbitBinder = binderFactory.getBinder(null,
			MessageChannel.class);

	RabbitProducerProperties rabbitProducerProperties = (RabbitProducerProperties) ((ExtendedPropertiesBinder) rabbitBinder)
			.getExtendedProducerProperties("output");

	assertThat(
			rabbitProducerProperties.getRoutingKeyExpression().getExpressionString())
					.isEqualTo("fooRoutingKey");
	assertThat(rabbitProducerProperties.getBatchSize()).isEqualTo(512);

	RabbitConsumerProperties rabbitConsumerProperties = (RabbitConsumerProperties) ((ExtendedPropertiesBinder) rabbitBinder)
			.getExtendedConsumerProperties("input");

	assertThat(rabbitConsumerProperties.getExchangeType())
			.isEqualTo(ExchangeTypes.FANOUT);
	assertThat(rabbitConsumerProperties.getMaxConcurrency()).isEqualTo(4);
}
 
Example #10
Source File: PrependHello.java    From cukes with Apache License 2.0 5 votes vote down vote up
@RabbitListener(bindings = {
        @QueueBinding(
                value = @Queue,
                exchange = @Exchange(value = RabbitMQConfiguration.EXCHANGE_NAME, type = ExchangeTypes.TOPIC),
                key = "prepend"
        )
})
public void onMessage(StringMessage msg, Message message) {
    String text = msg.getBody();
    System.out.println("PrependHello.onMessage - " + text);
    String result = "hello, " + text;
    template.convertAndSend(message.getMessageProperties().getReplyTo(), new StringMessage(result));
}
 
Example #11
Source File: ToUpperCase.java    From cukes with Apache License 2.0 5 votes vote down vote up
@RabbitListener(bindings = {
        @QueueBinding(
                value = @Queue,
                exchange = @Exchange(value = RabbitMQConfiguration.EXCHANGE_NAME, type = ExchangeTypes.TOPIC),
                key = "upper"
        )
})
public void onMessage(Message message) {
    String text = new String(message.getBody());
    System.out.println("ToUpperCase.onMessage - " + text);
    String result = text.toUpperCase();
    template.convertAndSend(message.getMessageProperties().getReplyTo(), result);
}
 
Example #12
Source File: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Test
public void testConsumerPropertiesWithUserInfrastructureCustomExchangeAndRK()
		throws Exception {
	RabbitTestBinder binder = getBinder();
	ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties();
	properties.getExtension().setExchangeType(ExchangeTypes.DIRECT);
	properties.getExtension().setBindingRoutingKey("foo,bar");
	properties.getExtension().setBindingRoutingKeyDelimiter(",");
	properties.getExtension().setQueueNameGroupOnly(true);
	// properties.getExtension().setDelayedExchange(true); // requires delayed message
	// exchange plugin; tested locally

	String group = "infra";
	Binding<MessageChannel> consumerBinding = binder.bindConsumer("propsUser2", group,
			createBindableChannel("input", new BindingProperties()), properties);
	Lifecycle endpoint = extractEndpoint(consumerBinding);
	SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint,
			"messageListenerContainer", SimpleMessageListenerContainer.class);
	assertThat(container.isRunning()).isTrue();
	consumerBinding.unbind();
	assertThat(container.isRunning()).isFalse();
	assertThat(container.getQueueNames()[0]).isEqualTo(group);
	Client client = new Client("http://guest:guest@localhost:15672/api/");
	List<BindingInfo> bindings = client.getBindingsBySource("/", "propsUser2");
	int n = 0;
	while (n++ < 100 && bindings == null || bindings.size() < 1) {
		Thread.sleep(100);
		bindings = client.getBindingsBySource("/", "propsUser2");
	}
	assertThat(bindings.size()).isEqualTo(2);
	assertThat(bindings.get(0).getSource()).isEqualTo("propsUser2");
	assertThat(bindings.get(0).getDestination()).isEqualTo(group);
	assertThat(bindings.get(0).getRoutingKey()).isIn("foo", "bar");
	assertThat(bindings.get(1).getSource()).isEqualTo("propsUser2");
	assertThat(bindings.get(1).getDestination()).isEqualTo(group);
	assertThat(bindings.get(1).getRoutingKey()).isIn("foo", "bar");
	assertThat(bindings.get(1).getRoutingKey()).isNotEqualTo(bindings.get(0).getRoutingKey());

	ExchangeInfo exchange = client.getExchange("/", "propsUser2");
	while (n++ < 100 && exchange == null) {
		Thread.sleep(100);
		exchange = client.getExchange("/", "propsUser2");
	}
	assertThat(exchange.getType()).isEqualTo("direct");
	assertThat(exchange.isDurable()).isEqualTo(true);
	assertThat(exchange.isAutoDelete()).isEqualTo(false);
}
 
Example #13
Source File: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Test
public void testConsumerPropertiesWithHeaderExchanges() throws Exception {
	RabbitTestBinder binder = getBinder();
	ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties();
	properties.getExtension().setExchangeType(ExchangeTypes.HEADERS);
	properties.getExtension().setAutoBindDlq(true);
	properties.getExtension().setDeadLetterExchange(ExchangeTypes.HEADERS);
	properties.getExtension().setDeadLetterExchange("propsHeader.dlx");
	Map<String, String> queueBindingArguments = new HashMap<>();
	queueBindingArguments.put("x-match", "any");
	queueBindingArguments.put("foo", "bar");
	properties.getExtension().setQueueBindingArguments(queueBindingArguments);
	properties.getExtension().setDlqBindingArguments(queueBindingArguments);

	String group = "bindingArgs";
	Binding<MessageChannel> consumerBinding = binder.bindConsumer("propsHeader", group,
			createBindableChannel("input", new BindingProperties()), properties);
	Lifecycle endpoint = extractEndpoint(consumerBinding);
	SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint,
			"messageListenerContainer", SimpleMessageListenerContainer.class);
	assertThat(container.isRunning()).isTrue();
	consumerBinding.unbind();
	assertThat(container.isRunning()).isFalse();
	assertThat(container.getQueueNames()[0]).isEqualTo("propsHeader." + group);
	Client client = new Client("http://guest:guest@localhost:15672/api/");
	List<BindingInfo> bindings = client.getBindingsBySource("/", "propsHeader");
	int n = 0;
	while (n++ < 100 && bindings == null || bindings.size() < 1) {
		Thread.sleep(100);
		bindings = client.getBindingsBySource("/", "propsHeader");
	}
	assertThat(bindings.size()).isEqualTo(1);
	assertThat(bindings.get(0).getSource()).isEqualTo("propsHeader");
	assertThat(bindings.get(0).getDestination()).isEqualTo("propsHeader." + group);
	assertThat(bindings.get(0).getArguments()).hasEntrySatisfying("x-match", v -> assertThat(v).isEqualTo("any"));
	assertThat(bindings.get(0).getArguments()).hasEntrySatisfying("foo", v -> assertThat(v).isEqualTo("bar"));

	bindings = client.getBindingsBySource("/", "propsHeader.dlx");
	n = 0;
	while (n++ < 100 && bindings == null || bindings.size() < 1) {
		Thread.sleep(100);
		bindings = client.getBindingsBySource("/", "propsHeader.dlx");
	}
	assertThat(bindings.size()).isEqualTo(1);
	assertThat(bindings.get(0).getSource()).isEqualTo("propsHeader.dlx");
	assertThat(bindings.get(0).getDestination()).isEqualTo("propsHeader." + group + ".dlq");
	assertThat(bindings.get(0).getArguments()).hasEntrySatisfying("x-match", v -> assertThat(v).isEqualTo("any"));
	assertThat(bindings.get(0).getArguments()).hasEntrySatisfying("foo", v -> assertThat(v).isEqualTo("bar"));
}