Spring Cloud Stream RabbitMQ wait for publisher confirms - spring

I am using Spring Cloud Stream with the RabbitMQ binder. I use the StreamBridge to send messages to a destination. I want to send a message with StreamBridge and after that synchronously wait for the publisher confirm (to make sure the message was received by the broker). Is that possible using Spring Cloud Stream? I have found the RabbitTemplate's waitForConfirms method and i have publisherConfirmType: simple and publisherReturns: true set in my configuration. But i don't know how to access the method with the RabbitTemplate since i don't use it because i'm using the StreamBridge. If i Autowire a RabbitTemplate and call waitForConfirms after my StreamBridge send call, it waits forever (nothing happens). I'm looking for an option like with the Kafka binder. There you can set the Producer to "sync" and "requiredAcks" to 1 to wait for publisher acks.
Thanks for any help!

Related

RabbitMQ Channel reuse (SimpleMessageContainer)

My spring boot application's is functionality it to listen to the messages on rabbitmq queue, do some processing in onMessage, and then publish the message on another rabbitmq queue. We are using spring-rabbit (1.7.2.RELEASE). We have configured listener using SimpleMessageListenerContainer.
My question is can i publish using he same channel on which I am reading he messages. Does spring-rabbit provides access to channel used by listener? so that same channel can be reused to publish?
Thanks,
Smita
If you use transactions (listener container), any operations performed by a transactional RabbitTemplate on the container thread will participate in the transaction and use the same channel.
If you are not using transactions, you can use a ChannelAwareMessageListener to access the channel the message was received on. See Message Listeners.
If you are using #RabbitListener you can add the Channel as a method parameter.
The current 1.7.x release is 1.7.9.

Pollable StreamListener or MessageSource for RabbitMQ Queue

I have Spring Cloud Stream Rabbit project that sends messages to an rabbit exchange errorEx in case of errors in the flow.
I want to periodically(once in 5 mins) listen from the queue and process it.
Is there any way I can have a Pollable #StreamListener?
OR Can I configure a rabbitMQ org.springframework.integration.core.MessageSource so I can build a IntegrationFlow with a Poller?
Spring Integration AMQP doesn't provide a pollable adapter. #StreamListener only supports Subscribable channels.
You could use a custom MessageSource that uses a RabbitTemplate receive() operation to fetch messages.
Or, you could use the message-driven adapter and stop()/start() it as needed.

Spring Integration - How to add message on topic before sending back acknowledgement for SOAP web service using declarative approach

I am consuming SOAP web service using inbound-gateway.We need to put message in kafka topic and return a synchronous acknowledgement to requestor using declarative way of spring integration. Is this possible ?
public Acknowledgement process(#RequestPayload MessagePayload payload) {
// perform validation & logic
// need to send message to kafka topic using declarative way
// sending synchronous ack to request originator
return new Acknowledgement();
}
The kafka outbound channel adapter has a sync property setSync(true) when using java config sync="true" when using XML.
The calling thread (web container) will block until kafka assumes responsibility. If you use a publish-subscribe channel, make the kafka adapter the first consumer, and a service to build the Acknowledgement the second consumer (use the order property in the consumers to ensure proper ordering).
Or you can use a KafkaTemplate directly from your controller.

How to get properly all queue messages from RabbitMQ in Spring?

I am using Spring, Spring-Websocket, STOMP for my application, and RabbitMQ as broker. I need to log all messages going through RabbitMQ to Postgresql tables.
I know that I can write #MessageMapping in Spring and log there, but my problem is that some clients talk to RabbitMQ directly through MQTT protocol, and Spring does not support it yet (https://jira.spring.io/browse/SPR-12581). Moreover browser clients talk through Spring to RabbitMQ using STOMP protocol.
RabbitMQ allows to track all messages using Firehose tracer. How to properly listen to amq.rabbitmq.trace topic from Spring? Or do I need to write separate Java app as consumer?
The Spring AMQP is for you!
You bind some custom queue to to that amq.rabbitmq.trace with appropriate pattern (e.g. publish.#) and configure SimpleMessageListenerContainer to receive messages from that queue.
It can be done even with pretty simple config: #EnableRabbit and #RabbitListener on some POJO method. Anyway the Binding #Bean must be there to attache your queue to that exchange.

How to write Apple push notification using Spring AMQP?

I am new to push notification. I would like to write a code using Spring AMQP which will send notification message to APN. I have .p12, certification and .pem files with me. Can anybody help me in writing the code using Spring AMQP which will send notification message.
Thanks in advance.
Spring AMQP is for sending messages to an AMQP broker, which in the case of spring is only RabbitMQ at this time. If you just have to use spring-amqp then you will need to create a producer using AmqpTemplate.convertAndSend. Then you will need a consumer that pulls messages off of the queue. See SimpleMessageListenerContainer and MessageListener for the consumer. Your consumer would contain the Push.alert("Hello World") code. Of course, the "Hello World" string would be replaced with whatever payload you are pushing to APNS.

Resources