Spring Security for Spring cloud stream with RabbitMQ as binder - spring-boot

I have a Spring boot application with Spring cloud stream enabled. This project contains both API endpoints and producer/consumer streams in it. In our case RabbitMQ is the binder. We have enabled Spring security but it works for API endpoints.
I need to know how security can be enforced for stream requests coming from RabbitMQ. Since no user context involved in this and the other services are publishing their requests to queue (our cloud stream has listeners for that queue) and not directly calling the API. So i am not sure how client credentials flow can be used in it.

#Vignesh
Now I'm not sure is it possible to share user content from message producer to message consumer.
I created an issue: https://github.com/Azure/azure-sdk-for-java/issues/23323
Please vote for the issue if you think this is necessary for you.
You can click +1 to vote, or you can add comments in the issue.
Further discussion in the issue is welcome.

Related

Spring and Google Cloud PubSub - subscribing to events

Following documentation, there are multiple ways to integrate Google Cloud PubSub events with Spring application:
Spring Cloud GCP has several modules for sending messages to Pub/Sub
topics and receiving messages from Pub/Sub subscriptions using the
Spring Framework. You can use these modules independently or combine
them for different use cases:
Spring Cloud GCP Pub/Sub Starter lets you send and receive messages
using helper classes and call the Pub/Sub Java client library for more
advanced scenarios.
Spring Integration Channel Adapters for Pub/Sub
let you connect Spring Integration Message Channels with Pub/Sub.
Spring Cloud Stream Binder for Pub/Sub lets you use Pub/Sub as
messaging middleware in Spring Cloud Stream applications.
I don't have full understanding - what are those different use cases mentioned, and how to determine, which module is best for which use case?
Application (Dockerized Spring Boot app, deployed to Kubernetes in GCP) I am working on is rather simple, it is expected to act upon received PubSub event, it is not going to publish any events itself.
Spring Cloud GCP Pub/Sub Starter module contains the java client classes for pub sub which will be used by your spring application to perform administrative and functional operations (ie. sending and receiving messages).
Spring Integration Channel Adapters for Pub/Sub module is utilized when your spring application uses Message Channels. This module will help routing message between message channel and pub/sub using channel adapters.
Spring Cloud Stream Binder for Pub/Sub module is used in Spring Cloud Stream Applications in order to utilize cloud Pub/Sub API.
Since, your application requirements are basic you can easily go for Spring Cloud GCP Pub/Sub Starter module. For more information you can refer to this Google documentation.

Need of listening incoming emails using spring boot

Looking for some ideas on how to retrieve incoming emails (Exchange Server) for processing, like retrieve some information and invoke a web service. The service should constantly listening for new emails. So far we are looking into this using Spring Boot, and Apache Camel or Sprint Integration. Cannot find a clear example on this.
Hope someone help on this.
Have a look at the this API -
https://www.independentsoft.de/jwebservices/tutorial/findmessages1.html
You can create Spring scheduler to poll the exchange server to get the messages arrived in given time interval.
See Spring Integration documentation about e-mail support: https://docs.spring.io/spring-integration/docs/current/reference/html/mail.html#mail.
The MailTests can serve as a good sample how to configure Spring Integration channel adapters for e-mail polling: https://github.com/spring-projects/spring-integration/blob/main/spring-integration-mail/src/test/java/org/springframework/integration/mail/dsl/MailTests.java.
The Spring Boot environment doesn't matter at this point: there is no any auto-configuration for mail polling, so everything should be transparent as long as as you use Spring Integration recommendations.
Unfortunately the official sample we have is still an XML, but should give you some ideas what and how should be configuration for IMAP or POP3: https://github.com/spring-projects/spring-integration-samples/tree/main/basic/mail

Using Spring Integration Router with Spring Cloud Stream

I have been trying to use the Spring Integration's #Router with Spring Cloud Stream with Kafka binding. My understanding is that when you return a List of channel names from the method annotated with #Router they should be produced to the destined Kafka topics. But I don't see the messages being produced.
Does Spring Integration's #Router work with Spring Cloud Stream. If not, what's the alternative and how do I programmatically route to channels selected at runtime?
What makes you believe that Spring Integration #Router has any effect in Spring Cloud Stream? It's a completely different framework.
Yes there are mechanisms to route FROM and TO in Spring Cloud Stream and they are described here.
I think the specific section of interest to your use case is Routing FROM, but consider reading the full section to understand the differences and mechanisms used.

Spring Boot Java8 Microservice Simple Message Subscription service

I am new to Microservice and JMS likes to know how can I
create a subscription
read the subscription
Using Spring Boot and JMS
To get started with Spring Boot and JMS use this getting started guide https://spring.io/guides/gs/messaging-jms/
Once you have that sorted then adding the microservices is just a matter of adding the Spring MVC and Rest components which you could first experiment as a standalone project and then integrate with the JMS application.
To get started with Spring Book and Microservices use the getting started guide https://spring.io/guides/gs/rest-service/
JMS not part of Java SE. You need Java EE or Spring.
I'm not sure queues are the best way to solve the problem.
I'd recommend Spring Boot.
Subscription maintenance isn't something that the queue would do.
A simple REST service would manage this nicely. You'll need a persistence layer to save subscription information.

Spring Cloud Config Server + RabbitMQ

I created spring cloud config server and client and they work as expected. I have added #RefreshScope to my client and I am able to see the new properties getting fetched after hitting /refresh endpoint. But I was told that when I deploy it in cloud foundry environment , I must integrate it with RabbitMQ in order for all the instances to receive the refresh message. Is it possible to point me to a link which explains this problem and solution in detail?
Spring Cloud Bus
This is what you need in order to propagate configuration changes to all of your servers via a message broker such as RabbitMQ.
GitHub Project
Documentation
Follow the instructions in the links above you're good to go.
So I assume your application runs as single instance configuration. In that case, you don't need spring cloud bus based refresh and just hitting the {app}/actuator/refresh would be enough. Only if you scale out your app, we would need such setup with a queue like RabbitMQ or kakfa.

Resources