How to deploy a nameko microservice - microservices

I've been reading through the nameko docs, and it is all good and clear, except for one part.
How do you actually deploy your nameko microservice?
I mean, it is clear how we deploy RESTful APIs in flask_restful, for instance. But with nameko?
If two microservices should communicate, how do we move them into the "listening" state?

I am not sure I understand your problem.
For each nameko service you define AMQP_URI constant that point to your RabbitMQ instance.
If each of your services have the same AMQP_URI, it make possible communication through sending rpc calls (where you have a queue per service endpoint) or using pub/sub messaging because service use the same RabbitMQ instance.
You can also have HTTP REST API. You must define endpoint in nameko service with http decorator (see example here: https://nameko.readthedocs.io/en/stable/built_in_extensions.html). In your confguration you have to define PORT for you web server, e.g. port 8000: WEB_SERVER_ADDRESS: 0.0.0.0:8000. And make this port accessible for the World.

Related

Myth over Microservice and Rest API

I would like to get some clarity on terminology of microservices.
Reference to the diagram mentioned below.
All Represents the Microservice Architecture
Microservice - Does it refer the service which are exposed as API to channel [ Be it browser / Native app / Host ] or even the service which not exposed [ Underlying
Generic
Orchestrated
Atomic
As per the diagram, Links from orchestrated to atomic were mentioned.
Does it have to be always a [REST/ HTTP over call] or is it can be normal Java library method call packaged in the same runnable package.
All tutorials says / goes 1 Microservice = 1 Rest based service or anything exposed as controller to be called from
Can we call library or DAO Generic Service also a microservice?
Microservice Architecture ViewPoint
Microservice ViewPoint 2
Comparison
Does it refer the service which are exposed as API to channel or even the service which not exposed
A microservice is a service that serve a business need - they are "Componentization via Services" - componentes of a bigger system, so they don't necessary need to be exposed to external world, but they can be.
Does it have to be always a REST/ HTTP over call, or is it can be normal Java library method call packaged in the same runnable package.
Microservices communicate over network, but it does not have to be HTTP / REST, it can also be a Kafka topic or gRPC or something else. The important part is that they must be independently deployable e.g. you can upgrade a single microservice without needing to change another service at the same time.
See Martin Fowler - Microservices - 9 characteristics for the most commonly accepted definition.

auto scaling and load balancing Spring boot restful service

I have a Spring boot RESTful service endpoint. this service should be available on port:8080 always. but when too many HTTP requests arrive, I want it to be scaled up automatically. and also scale down if number of requests falls down. for scaling up/down, I have no problem, because I can use Spring Cloud Eureka + Jenkins. but the problem is that, they create service instances with different port numbers (obviously). but I need somehow to mask the whole scaling up thing from clients. because they should only use the port 8080. so I am confused, how I can load balance the requests on port 8080 to my multiple instances, which are running on other different ports. appreciate if you can help me.
Use zuul routing to load balance your instances.

Microservice synchronous communication - service to service or message broker

I am developing a series of microservices using Spring Boot and Kafka. For asynchronous communication, I am using Kafka which is working well.
I have a use case where I require synchronous communication between two microservices (a user registers a profile via the user profile service which needs to create an auth account in the auth microservice).
Should I just call the auth service directly (service to service communication) or should I use Kafka?
Any examples or best practise advice would be appreciated.
There are multiple factors that can drive your decision:
Required any acknowledgement from your Auth Service?
if yes:
For Immediate acknowledgement, use http
For not so immediate acknowledgement, Callback pattern can be implemented.
In your case, user profile sends request via Kafka to auth service and it calls
endpoint of user-profile to report status of the job.
if no:
Use queue one for better resiliency.
Error Handling
Think of auth service failure? What should be the reaction of user service ?
if on auth-service failure, user-service should also fail
Use http
if on auth-service failure, user service should not fails.
Use queue
Ideally in user creation and authentication realtime response is given to the client side but if it involves complex process or tasks post user creation queue should be preferred.
For multiple microservices synchronous interaction and to work on their API responses you can build a aggregator service which could serve as a communication medium between different services and work alongside your kafka queue consumer service.

Share Websocket Session between Spring Micro Service

I've a Spring boot Application for Web sockets. I'm not using Stomp Web socket.
Is there way we can share web socket sessions across multiple instance of micro service.
Is there a way we can save websocket session in Redis or cassandra?
My use case is, i've multiple instance of my micro service is running, which is listening a kafka queue, so when a message received, i need to send it to the client using web socket session.I'm saving the session in the micro service as a MAP. My problem is any one of my micro service is getting the message, if the session is not available with that micro service the message is not going to the client.
If i'm able to save the websocket sesssion in REDIS or Cassandra, i can query the session and sent to the client.
I can't use Stomp web socket as per the requirement, it has to be normal websocket.
You can't. You have to implement some sort of routing from whatever receives the kafka message, to your micro service.
One simple way to do it would be to store in any datastore (mongo, redis, etc) the IP of the service instance for a given client. That way when you get the message from kafka, an you know who is it for, you lookup which machine has the websocket session for that client. Then you call some http endpoint on that IP that you implement to relay a message for a session it's handling.

Proxy Service & Business Service

Can i use a proxy service without a business service while configuring message flows in Oracle service bus? If so is what scenarios would we use it?
You can create a proxy service that does not use a business service.
Some reasons for such an approach is to create a common proxy module that is used by other proxy services that may do some common message processing before forwarding to a business service.
I think you cannot create a proxy service without a business service call in OSB, but you can call dummy business services that publish on a JMS topic that nobody listens on. This kind of proxy service could implement data transformation (e.g. XSLT) between the request and response, or enrich the response with data retrieved from a lookup table (fn-bea:execute-sql()).
A service bus, like OSB is meant to provide a façade to back-end (business) services: route to and compose existing services. What you are asking for is to create new back-end services which is more suited for Java EE servers or Oracle BPEL.
Update: You can create stand-alone proxy service, if you use pipeline pair and stage, but no route steps.
You can create a proxy service without a business service. A simple scenario is suppose you want to fetch the data from the queue, could be jms or mq, and you don't want to do anything with that data. You just simply want to empty the queue and do not want to store the message. In this case, your purpose can be fulfilled by simply creating a proxy service.

Resources