I am new to Microservices architecture.
I want to create a microservice using Netflix OSS.
I want my architecture to look some thing like the one described here.
http://callistaenterprise.se/blogg/teknik/2017/09/13/building-microservices-part-8-logging-with-ELK/
However I want one of my microservice, (which is behind the Zuul Reverse proxy) to consume events from a Kafka events(which is from some other team).
I am not sure If this is a good idea, since this will expose my microservices, which is supposed to be abstracted from outside world behind my Zuul wall.
Is there any other way. Can I use my Zuul to consume event streams from kafka and push to my microservice. If yes, how do I stream from my Zuul to microservice?
Zuul will redirect your request to A service HTTP XXXX port /api/v1/input. This microservice as a producer will put message to kafka channel. After kafka consumer will get message and store or analyze. Another microservice can read from database and return response after frontend request or do push using Server Sent Events or Vertx message bus....
Related
I have two microservices(A and B).
Service B receives HTTP requests from the UI. Based on some conditions service B requires data from a DB which only service A has access to. So I would need some communication mechanism between service B and A. So service B would internally call service A, retrieve some fields from the response from service A and eventually send the final response to the client.
I'm used to spring boot framework and AWS cloud resources. I'm new to reactive programming. The services are built using micronaut framework and utilise reactive programming. Kafka is also used as a messaging system.
In Spring boot, I would use a rest api and use webclient to make async calls from service B to service A. But with a rest API, I'll have to handle security and authentication as well.
With reactive programming in micronaut and kafka available, is there a better way for these microservices to communicate?
Update 1:
If a message bus is used, in an event-driven way, service B can't receive the response from service A right? Unless service B notes the message ID and service A publishes a message back with the required data from it's DB and mentions the appropriate message ID for that data sent.
Micronaut can also use both HTTP and Kafka.
Service-to-service communication simply requires a network link. Message buses / brokers are completely optional, but offer a way to buffer events and/or handle downtime.
Reactive programming doesn't really change this. It doesn't change the security model, either. Kafka and REST clients can still use TLS, and have authz restrictions.
DB which only service A has access to
You could use Debezium; pulling the data into a Kafka topic from the database (if supported), then build a local, queryable KTable within "service B", rather than needing "service A"'s API at all.
I've made a REST connector to push NodeJS Service response to Kafka but now I want to write or use a REST sink connector to expose my API response stored as message.I'm able to get Kafka message over websocket, what is standard way to expose other than API Gateway using plain Apache kafka(no third party platform)
works with WebSocket but want to expose as API Gateway or something reliable usign kafka
No third part platform just Apache kafka
Currently I am using spring cloud Netflix stack for development of my microservices based application. where I have used different services provided by Netflix stack like
EUREKA : for service registration and discovery
ZUUL : for proxy gateway and
RIBBON : for load balancing
now we want to use Apache kafka for inter-communication between microservices where kafka will have different topics to which our microservices will subscribe,
now real problem starts here is how the load balancing, proxy gateway and eureka will work here.
few questions I have in mind which are really confusing me are
1. how ribbon load balancing will work here, since while using HTTP we are using #loadbalanced restTemplate but now this will not be the case.
2. how service calls will be distributed among different instances of a same service
3. whether Zuul and Eureka are needed here or we just need to ignore these and go with kafka load balancing and service discovery through topics.
I gooled but not found any satisfying answer if any expert here can help me will be appreciated, if there is any similar questions that can also help.
Thanks in advance.
For your above use-case , if you are going to use kafka for inter microservices communication , there is no need for any spring-cloud-netflix component. You can publish to a topic and have consumers in microservices consume from the topic. Load balancing will automatically happen depending upon number of partitions in the topic.
For example , lets consider your topic name is test and it has 4 partitions . If you have deployed 4 microservices with each consisting of a single Kafka Consumer consuming from topic test then each consumer will consume from 1 partition on the topic test. So , load balancing will automatically happen.
The spring-cloud-netflix components are mainly meant for inter-microservices communication when there is network calls involved between microservices .
For example -
Lets consider two applications A and B . You have 4 instances of Application A deployed and 4 instances of Application B deployed . The entry-point for the consumers of your system is Application A . Here , you will use an Api Gateway like Zuul . As for Eureka , you will have all your instances deployed register in it. When a request comes into Zuul which needs to be forwarded to Application A . All the instances of Application A will be fetched from Eureka (4 in our case) and then being provided to a load balancer Ribbon who will chose which url should be called . Zuul will then forward the request to that instance of Application A.
Some links you should look at are-
https://github.com/Netflix/zuul/wiki/How-it-Works
https://github.com/Netflix/ribbon/wiki/Working-with-load-balancers
https://blog.asarkar.org/technical/netflix-eureka/
I have just started learning Kafka. So trying to build a social media web application. I am fairly clear on how to use Kafka for my backend ( communicating from backend to databases and other services).
However, I am not sure how should frontend communicate with backend. I was considering an architecture as: Frontend -> Kafka -> Backend.
Frontend acts as producer and backend as consumer. In this case, frontend would supposedly have all required resources to publish to Kafka broker (even if I implement security on Kafka). Now, is this scenario possible:
Lets say I impersonate the frontend and send absurd/invalid messages to my Kafka broker. Now I can handle and filter these messages when they reach to my backend. But I know that Kafka stores these messages temporarily. Wouldn't my Kafka server face DDOS problems if such "fake" messages are published to it in high volume, since it is gonna store them anyway as they dont get filtered out until they actually get consumed by backend?
If so, how can I prevent this?
Or is this not a good option? I can also try using REST for frontend/backend communication and then Kafka will be used from backend to communicate with database(s) and other stuff.
Or I can have a middleware (again, REST) that detects and filters out such messages.
Easiest way is to have the front end produce to the Kafka REST Proxy
See details here https://docs.confluent.io/1.0/kafka-rest/docs/intro.html
That way there is no kafka client code required in your front end and you can use HTTP(S) with standard off the shelf load balancers, and API Management tools.
Could you not consider the other direction, to use Kafka as a transport system for updating assets available to frontend ? This has been proposed for hybrid React / NodeJS/Express solutions.
I have a rest based application deployed in server(tomcat) ,
Every request comes to server it takes 1 second of time to serve, now I have a issue, sometimes Server receive more request then it is capable of serving which making server non responsive. Now I was thinking if I can store the requests in a queue so that server can pull request and serve that request and handle the pick time issue.
Now I was thinking can Kafka be helpful for this, if yes any pointer where I can start.
You can use Kafka (or any other messaging system for this ex- ActiveMQ, RabbitMQ etc).
When WebService receives request, add request (with all details required to process it) in Kafka queue (using Kafka message producer details)
Separate service (having Kafka consumer details) will read from topic(queue) and process it.
In case need to send message to client when request is processed, server can push information to client using WebSocket (Or client can poll for request status however this need request status endpoint and will cause load on that endpoint).
Apache Kafka would be helpful in your case. If you use a Kafka broker, it will allow you to face with a peak of requests. The requests will be stored in a queue as you mentionned and be treated by your server at its own speed.
As your are using tomcat, I guess you developped your server in Java. Apache Kafka propose a Java API which is quite easy to use.