Sending message to single person using Spring STOMP websockets - spring

On the internet I've found some info on how to accept and send messages using Spring and STOMP, however I did not find any good examples on how to send a message to a single user. Only how to broadcast them to every single one. Are there any good examples on it?
I basically want to run one or two controllers with STOMP in a Spring MVC structure, so I can authenticate people outside of the websocket, and later on tie that authentication to the STOMP controllers, and for that I obviously need to be able to send messages to individuals.

There is a reasonable spring blog post which covers this:
http://assets.spring.io/wp/WebSocketBlogPost.html
The source code is on github (and linked from the blog).

There is a concept of User Destinations where messages can be bound to a specific destination belonging to a user's session.
There is this article from the Spring docs that explains it nicely. Hope this helps someone.

For anyone looking for the same answer with a nice code example, I've found this repo: spring-websocket-chat

Related

RabbitMQ filtration to specific Users

I have an architectural problem.
I know what represents a (fanout, direct, topic, headers) exchange, bindings, queues and almost everything about message architectures. I have the following problem and I need some pieces of advice.
I would like to implement notification logic to my application, where each user will receive in real-time notification only intended for him. ( Actually, I don't want mention what are my UI and BE languages/frameworks, because of an additional level of abstraction) The UI will make a connection to RabbitMQ with WebSocket, SockJS and STOMP. My UI will be only a consumer, the BE is the writer - that one, which will add some Messages to RabbitMQ.
It's perfectly clear to me if I have a direct Exchange with routing key, which uniquely to identify the specific user (for example: my-routing-to-empoyee-with-id-1) and N-number of Queues for each user. This is too heavy to me (I don't know actually whether is normal situation to have so much queues).
Is there any solution, where I can use only one Queue and the message to be delivered only to user for who is intended ?
I know a solution, where I can have a topic exchange and to have one writer and many subscribers, but on this way, I can filter the message only on clients level, which is not so secure. :(
Actually, I found a very interesting article, which describes me a problem that I have pretty well.
What I want is called Selective Consumers and for Enterprise Integration Patterns this is an anti-pattern and we should not use it.
For more details, all who want can read this article: https://derickbailey.com/2015/07/22/airport-baggage-claims-selective-consumers-and-rabbitmq-anti-patterns/

Spring integration with http inbound gateway

Currently am working with spring integration with web service. I googled in many places including git but i could find good example to proceed with. I've configured the http inbound gateway and its not receiving the request from http client. Also am not sure what are the configuration needs to be added.
I couldn't find any better tutorial or steps to proceed. Any help much appreciated. Is it a good practice use http inbound gateway to receive http request as i couldn't find proper step or documentation to proceed.
Any help or guidance or example sites much appreciated.
Thanks,
Krish S
If you are facing the problem, it would be better to share the config.
You can find more info in the Reference Manual.
Also you can take a look into the Samples.
Or even you can take a look into our Test Cases. For example HTTP Proxy.
All that info are available from the main Spring Integration site.
Sorry for the bunch of links, but such a blurred leads to the common answer.

internal mailbox in Spring MVC

I would like to implement an internal mailbox in Spring MVC application. I tried to find something out myself and I surfed RabbitMQ, JMS, AMQP etc. but I am not sure if it is what do I need. I want to allow my users to send messages among themselves but I do not mean a chat, it should be an internal mailbox, persisted to database. I am sure if I should one of mentioned frameworks and do persistance or there is another way? Could you give me some advises or links to get started with my problem?
thanks
Why do you need JMS or anything like that? I have typically used those when I needed real-time sort of messaging on my site. For a simple mailbox, just write the data to the DB on send and have a method to check if a particular use has messages waiting. If you want to get fancy, you can AJAX-enable said method and have it check on some sort of timed loop.

Does ActiveMQ Apollo implement JMSXUserID or something similar to help track authenticated users?

I know that ActiveMQ supports the JMSXUserID property:
http://activemq.apache.org/jmsxuserid.html
I'm trying to use Apollo (an ActiveMQ sub-project) instead of ActiveMQ, and at the moment I'm stuck trying to figure out to replicate that same behavior in Apollo.
I'm not picky about the mechanics, but in a nutshell I need some way to tag every incoming message from an authenticated user with an identifier that lets me know which user sent which message, but in a way that users can't spoof by setting themselves. This is basically exactly what JMSXUserID is used for by ActiveMQ, but I can't seem to figure out how to do the same thing in Apollo.
What am I missing?
I'm finding this especially difficult to Google for, since ActiveMQ links to Apollo on every single one of its pages so most of my search results are unhelpful.
Thanks in advance.
Apollo's user manual describes how you can configure apollo to automatically add a user header which is set to the sending user's id.
Basically you want to configure the connector's stomp protocol with something like:
<connector id="tcp" bind="tcp://0.0.0.0:61613">
<stomp>
<add_user_header separator=",">JMSXUserID</add_user_header>
</stomp>
</connector>
Unfortunately the Openwire protocol does not support this yet. Issue APLO-213 is open to address it.
Does Apollo even support JMS?
from web page: http://activemq.apache.org/apollo/
In it’s current incarnation, Apollo only supports the STOMP protocol but just like the original ActiveMQ, it’s been designed to be a multi protocol broker. In future versions it will be adding OpenWire support so it can be compatible with ActiveMQ 5.x JMS clients.
To solve your very problem at hand, can't you simply add a header with the userid in the code?
Just grab it from the OS, say you are using Java, then you could perhaps use something like
System.getProperty("user.name")
and attach it to a STOMP header. This is, however, an issue for the client lib (stomp library, if any is used) rather than the server itself.

How to send Email notifications (user registered, import completed) using Spring

I guess this is not a specific question, but getting ideas on how to.
We have a Flex - Spring - JMS - Hibernate webapp. Our requirement is to send automatic emails when some event occurs (new user registered, user performed an import successfully). We will have the Email addressess, content, Subject, etc in the DB. We can have the Mail Server settings hardcoded (or in the db). I would like to have this as a separate service for reusabulity. I would like to get your inputs on how to achieve this and also provide some optimal solutions on what would be the best way. Do I use JMS for this or Spring's Java Mail Sender. Which is more efficient and the latest.
Hope my question isn't too vague. Your inputs are appreciated as always :)
Thanks
Harry
Here are few low-hanging choices you have (from best to worst):
Spring Email support
The Spring Framework provides a helpful utility library for sending email that shields the user from the specifics of the underlying mailing system and is responsible for low level resource handling on behalf of the client.
This is the simplest approach (not counting coding to raw JavaMail API). If you need to just send that e-mail, you don't need nothing more. You can esaily inject JavaMailSender wherever you need it.
Email support in spring-integration
Spring Integration provides support for outbound email with the MailSendingMessageHandler. It delegates to a configured instance of Spring's JavaMailSender [...]
This solutions is built on top of 1. If you need a reusable service with enterprise integration patterns bundled (like filtering, routing, enhancing, etc.) and great flexibility. If your application does a lot of integration, this might be a smart choice but is a bit more heavyweight when it comes to maintenance.
SMTPAppender in logback
The SMTPAppender accumulates logging events [...] and sends the contents [...] in an email after a user-specified event occurs. SMTP email transmission (sending) is performed asynchronously.
This Logback appender is typically used to send an e-mail yo support/administrator when an ERROR occurs, containing error event itself and few previous events. But with a little bit of configuration you can easily use to it catch specific events in your application (triggered by logging statements) and send messages. However it will be a bit cumbersome and not flexible enough.

Resources