I have been learning how to use spring framework and so far so good. I have created an app from Spring Initializr - http://start.spring.io/ and i have been able to setup numerous controllers and even setup security and everything works out.
I am running my app on Apache Tomcat. I now want to use Spring AMQP and the way i want to use it is like this. I shall execute a controller method in the browser and that adds a message in the queue which should be consumed by a consumer,possibly a threadpool powered consumer and return the result to the user.
For instance i want to add a message to the queue and return json to the user.
Since i executed the add message from a controller, i am expecting to show the response to the user.
After going through the rabbit mq docs, i think RPC would help me publish the message to the queue and it shall be consumed and the result returned to teh user. I setup the rabbit mq example using php and i saw it work.
However, upon looking through the spring amqp docs,i came across this three
-Message Listener https://docs.spring.io/spring-amqp/docs/1.3.5.RELEASE/reference/html/amqp.html#containerAttributes
-Listener Concurrency https://docs.spring.io/spring-amqp/docs/1.3.5.RELEASE/reference/html/amqp.html#listener-concurrency
-Request/Reply Messaging https://docs.spring.io/spring-amqp/docs/1.3.5.RELEASE/reference/html/amqp.html#request-reply
-RPC https://www.rabbitmq.com/tutorials/tutorial-six-spring-amqp.html
My question is,if i wanted to let the user get the result, would i pick RPC or Request/Reply Messaging or are they the same thing?
Second, in the last RPC example i did, i started the listener separately like java_listener.java to be able to consume the messages.
Since i started my app with spring intilizr and i am running tomcat, will i need to start the consumer separately from the tomcat process?.
Thanks.
Related
In my Spring Boot app, I implement an endpoint to send email to a single user. At this stage, I need the following implementations:
Sending mail to multiple users (less than 100 users)
Schedule sending time
My questions:
1. Although I have no previous experience for RabbitMQ, I want to start to use it and I think I can use it for sending email to multiple user. Is this scenario suitable for using RabbitMQ?
2. At this stage, I think of using a proper scheduler for Spring Boot. Does RabbitMQ supports scheduling to periadically send mail to multiple user? If not, which library should I use for scheduling that is suitable for Spring Boot and RabbitMQ ?
No, RabbitMQ should not be used as a task scheduler. RabbitMQ is a message broker (for example, sending a message from one microservice to another).
For tasks scheduling, you can use the ScheduledThreadPoolExecutor/Timer,/Quartz(see: github repo)/Spring Scheduler...
Example: you can create a microservice that, using RabbitMQ, will receive asynchronous tasks to send/schedule emails, using, for example, Quartz + JDBC + Spring-mail.
I also advise you to look at the examples below:
example with Quartz + MySQL + SpringBoot
another example
I have a Service Bus Queue which is Session-enabled. For example, let's say that messages are divided into Session-1 and Session-2 in the queue.
I am trying to create two JmsListeners for the queue, one processing messages with Session-1 and another for Session-2.
In the Azure documentation for using Spring Boot with a Service Bus Queue I see that there is an example of how to set the Session ID while sending a message via JMSXGroupID, however there is no example on how to receive messages for a particular session.
My only idea at the moment is to use a MessageSelector to filter.
It looks like it is not possible as of now, see this Github issue.
I need to write tests for an application which is integrated with Kafka and sends event messages to a remote Kafka server. My goal is to ensure, as a consumer, that those messages are created and to check their content, if that is possible.
I looked through Kafka documentation and found the consumer API is where I am supposed to start but I’m unsure how to start implementing it.
If you want to stay away from programming much, you can configure Mockintosh's "Validating Consumer" (https://mockintosh.io/Async.html#validating-consumer).
Then you can validate the facts of message created via simple HTTP calls to Mockintosh API. Also there is UI to see those messages ad-hoc.
The documentation says that when spring cloud config server detects configuration chages it fires an RefreshRemoteApplicationEvent. But documentation said nothing about how that event is handled. So is it true that each application which receive such event shoud handle it by itself? E.g it is not required to refresh entire Spring context when such event was received?
I think the documentation only talks about the server side, i.e. the Spring application that talks to the git repository and exposes the condensed information to interested clients. In this process, for example using webhooks, the server can be informed about changes in the git repository, and in turn sends out events to applications that might need to be re-configured.
Your question seems to be concerned about the client side. If your application uses Spring Cloud Config, it should automatically request the new configuration data as soon as the event described above arrives at the client. This in turn should mean that the new configuration values are available or some configured behaviour (log level?) changes.
To actually make the server fire an event that arrives at the client, the documentation suggests Spring Cloud Bus. If you create (for example) a RabbitMQ instance, and make this available to both your clients and your server, Spring automatically attaches to this system and is able to process messages. Additionally, the Spring Cloud Config server automatically sends the desired events using this system, and the clients automatically process these.
In short, if you add Spring Cloud Bus to all involved applications (and make the system used by it, e.g. RabbitMQ, available to them), everything works as expected.
Could someone help me on this,
I have created simple web services using axis2 , apache and tomcat. This web service has a queue that keeps xml files sent from a client, so whenever a client calls a method on the webservice, the webservice loads this xml to its queue. Now I want to have a thread running in the webservice which monitors this queue, and if there are items in the queue takes some action.
But my problem is that the webservice is invoked only if a client calls one of the methods on its interface. But I need this thread to be running on webserbice. Could someone tell me is there are is a way to do this?
When a client invokes a method on the webservice, it does not consider previous method invocations. This means that it does not keep track of data in the queue, for each invocation it creates new queue.
If you need background threads in a web application you must manage them inside a ContextListener registered in web.xml. You are then notified when your web application is started and stopped.
Sounds like the perfect use case for JMS/message driven beans. Spring JMS provides these facilities without having to use a full-blown J2EE container, so tomcat will fit here. Active MQ can provide the messaging engine.
Essentially, your web service would put a message on a queue and a message driven bean (or message driven pojo) would read them off the queue and process. Using JMS would have the advantage that you'd be able to reconfigure the message driven bean to sit on a separate host if you're load on the server grows. It'll also mean you'll be able to move to different app servers with ease as JMS is a standardised solution.