Spring-integration: Put message into JMS queue only if e-mails has been sent - email

I want to send a mail and only if this works put a message into a JMS queue.
How can I do it? I couldn't find any mail:outbound-gateway.
OBS: By now a am using publish-subscribe-channel, but this is not exactly what I need.

OBS: By now a am using publish-subscribe-channel, but this is not exactly what i need.
Why not?
There are several techniques to do this:
Publish subscribe channel with the JMS endpoint the second subscriber (mail order="1", jms order="2") (with ignore-failures="false" - the default).
Recipient List Router
Expression Evaluating Request Handler Advice

Related

Ensure at-most-once semantic with SendGrid Mail API

I have an [Azure Storage] queue where I put e-mail messages to be sent. Then, there is a separate service which monitors that queue and send e-mails using some service. In this particular case I'm using SendGrid.
So, theoretically, if the sender crashes right after a successful call to SendGrid Mail Send API (https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html), the message will be returned to the queue and retried later. This may result in the same e-mail being delivered more than once, which could be really annoying for some type of e-mail.
The normal way to avoid this situation would be to provide some sort of idempotency key to Send API. Then the side being called can make sure the operation is performed at most once.
After careful reading of SendGrid documentation and googling, I could not find any way to achieve what I'm looking for here (at most once semantic). Any ideas?
Without support for an idempotency key in the API itself your options are limited I think.
You could modify your email sending service to dequeue and commit before calling the Send API. That way if the service fails to send the message will not be retried as it has already been removed from the queue, it will be sent at most once.
Additionally, you could implement some limited retries on particular http responses (e.g. 429 & 5xx) from SendGrid where you are certain the message was not sent and retrying might be useful - this would maintain "at most once" whilst lowering the failure rate. Probably this should include some backoff time between each attempt.

What's the difference between the send and publish methods of Vertx's EventBus?

I'm having my first contact with Vertx's EventBus and I realized there are two ways to submit a message. Used the send or publish method. I ask: What is the practical difference between using these two methods and in what scenario do they use each one?
Both send and publish are used to send a message to an event bus address. However there are some differences between the two.
By using publish:
A message is sent to one or multiple listeners
All handlers listening against the address will be notified
No answer is expected from handlers
By using send:
A message is sent to one and only one handler registered against the event bus address.
If multiple handlers are registered, only one will be notified. The receiver will be selected by a "round-robin algorithm" as per the docs.
The receiver can answer the message, this answer can be empty or contain a response body. A response timeout can also be specified.
In practical usage, publish is quite useful to inform that an event has occured, whereas send is quite handy for asking a treatment where the response matters.
Conceptually, publish uses the publish/subscribe pattern whereas send uses the request/response pattern.

Message brokers - "message has been read" acknowledgment solution

I am implementing a service that dispatches messages to clients using an arbitrary message broker. A single user may have multiple clients and the message will be dispatched to each one of them. Once the user has read the message on one client, I want the message removed from the user's other clients.
Do message brokers typically implement this functionality, or will I need a custom solution?
For a custom solution, I was thinking that the broker could maintain a separate reply topic to which a client will deliver a message to say that the user has read the message. The service can consume messages on this reply topic, and dispatch another message to the user's other clients that tells them to remove the message.
Is this how such a solution might typically be implemented?
If it helps, I am considering using MQTT as a message protocol.
There is no concept of even end to end message delivery notification in the MQTT protocol1, let alone read notification. You are likely to need to implement this your self.
If I was doing this I would have 2 topics per user something like this:
[user id]/msg
and
[user id]/read
I would make the payload of the messages delivered to the [user id]/msg contain a message id. I would then publish the message id on the [user id]/read topic. All clients would subscribe to both, that way they could easily mark as read/remove messages as they were consumed on other clients.
1confirmation for higher QOS levels are between the publisher and the broker and then between the broker and the subscriber

E-mail Communication

How to get total email conversation with single common identifier in all email messages using java. javaMail API and JMS is giving sender and receiver message id which is different. I need the common identifer which will specify the communication thread.
There is no such thing. If you're trying to correlate messages into a "thread" or "conversation", see this.

How cometd server send response to /meta/connect message

How CometD send response to a /meta/connect message.
Also how cometd receive/send message received on any broadcast channel. Are there any message queues involved?
If there is queue involved then will /meta/connect will also be en queued into this? Does this queue exist on client side as well?
You may want to read the CometD documentation, in particular the CometD Concepts.