node/rabbitmq : choreography asynchronous and reponse - node.js

Hello I have a question about choreography,
I know it's asynchronous, but in this context:
a requisition in endPoint / addEmployee (where to create an employee the existence in the department is necessary), I would check for an employee and send a message in my department queue to verify the existence and also sign up in the queue to hear the answer, would that be choreography?
Or when confirming the existence of the employee, should I create and send the response already? or can i send the response after consuming the departament queue?
Or in this case, would the orchestration be correct?

If I understand correctly you are receiving a request or a message which contains information to create an employee. One of those field is department name or id. And you would like to validate existence of this department information from department service. Is my understanding correct? If so I would say a lot easier solution would be keeping a basic department data on your employee service. You can get department created, updated events from department service and sync your data instead of asking for each and every employee.
With this solution you wont have a dependency between services. You will just listen the topic or queue to which you wont know where the message comes from which is total opposite of the coupling.

Related

DDD Microservice Saving releated service data

I have product service, category service, promotions service, search service.
When User want to add product. CreateProductRequest come to product service. Request includes product data and datas of other services like categoryId,uncalculated price , too. After product is added. I need to send other servie datas. Category service needs productId and CategoryId. Promotions service needs productId and price.
After creat eproduct transaction commited;
1) I put all data in ProductCreatedEvent that includes saved productId, categoryId, uncalculated price etc. Every service get what it needs from event and save to own db. I publish event with RabbitMQ
2) Send via seperated commands to services.I send commands with RabbitMQ
And What If there is no category that id come with event and Category services didn't save. But Product saved at product Services ?
or what do you suggest ?
To answer the question, it's important to keep in mind the difference between a command and event. A command is a request to do something. An event is a record of something that has happened. One key difference is that a command can be rejected.
When looking at your use case, publishing events to other services makes the most sense. The product has been created and you are notifying the other bounded contexts that care about the change. If you issue a command, you are telling other bounded context to make a change that may or may not fail.
That said, you each bounded context may receive the event and produce a command within their own context to update aggregates managed within. As such, the difference is subtle between these two:
- Issue a command to each bounded context
- Issue an event to each bounded context and they can then trigger a command as needed
But given the above, the notification of the creation of the product should not fail. It has happened already. From there, each context can decide what to do about it.

DDD how to design basket service

I have 2 option.
1)when addItemTobasket request come. gRPC request to product, pricing, user service and get informations . and save them to cart db.
Or not fetch other service information. Save only references like id. And save basket db. When get basket request call gRPC request aggragate all service datas as viewmodel and return that.
2) create shared redis session server and when addeditem to cart event raise itemAddedToCart includes reference ids. And main services consume that event. Product service get product with id that come with event and write Product info shared redis. pricing service price etc. When getbasket request come data is ready in redis.
For 1) it coupled all servies. it is not good for ddd.
For 2) it is async. When user add item to cart. Waits a responsr success or failed.
If there is better best practice please share with Me.
Honestly I'd say just go with option 1. It's not as complex as there aren't so many interconnected parts. Also depending on the size of your app, that kind of coupling is easy to remove later on when you gain a better understanding of what is going on.

What is the Get URL to fetch TEAM roster or user profile information?

Can someone please share the postman to fetch TEAM roster or user profile information. I am referring to https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/get-teams-context?tabs=json
The Url you need is this: [serviceUrl] + "/v3/conversations/{teamId}/members/"
and it is based on two variables: the "teamId" is obviously different per team. However, the first part of the address (called the ServiceUrl) can also vary between teams, based on where they might be hosted, and you need both.
It sounds like, from the link you sent, that you already have a bot? If so, your bot can retrieve both of these required parameters. One way is that, whenever a user sends a message to the bot, to get the ServiceUrl and TeamId that are sent in the incoming "activity" object that. However, if you want it even earlier than this (i.e. before a user even sends a message to the bot), have a look at the conversationUpdate event here which will fire right when the bot is first added to the conversation.
Does that help?

job queue in nodeJS

I am working on a personal project where I want to automate the TA assignment system. I want to use Node and MongoDB for this. Though I have some idea about MongoDB, I am new to NodeJS. The aim of the projest is to do something like this :
A school administrator submits the course for which he/she wants to hire a TA.
The database is already populated with eligible students(more than two). The fields assoc with each student is [Student ID, Seniorty(sophomore,junior,senior),Course Taken or not, grade,presentStatus(Avlbl/Hired)]
At any point of time, the school admin requests a TA for a course, he gets the most senior eligible student available in the db.
Once the student is assigned, his status is changed to Hired.
I was planning to implement this using a queue. (Storing all the available students in that course in a queue and assigning the TA-ship to the senior student available in the front of the queue). As soon as he/she is assigned a TA, they are removed from the queue and pushed back into the db with the PresentStatus as 'Hired'. The problem I am facing is, I am not able to understand how I should be implementing the functionalities of the queue using NodeJS. During my research about the approach, I found something related to monq and a blog as well where they have discussed implementing it with Kue(backed by Redis instead), however I am still not able to visualize how this idea should be implemented using queues in NodeJS. Any help would be appreciated.
RabbitMQ is an option you are looking for.
You have to create a message sender and message consumer. The consumer will have a corresponding queue. Once the queue is filled with a message, the consumer will grab it and do it's process. In your scenario, it checks the student's status and then change him/her as hired in your database. What your sender does is that it packages a student's information and put it in the consumer's queue. I can imagine what will be happening in your case: a student submits request on his/her side. The node.js api receive it and pack information. Then it sends it to your customer queue. Your customer will process it if it's free. If it's busy, the information will be waiting in the queue. I recommend you to use json for students' information when different components have to communicate.
Here is the official website of RabbitMQ: https://www.rabbitmq.com/getstarted.html
Hope it helps.

DDD, external datas and Repository

I'm thinking to use DDD for our next application. I have already found a lot of interesting papers and answers but cannot find a solution to my problem :
We have an SOA. architecture where some services are known as master of their datas. That's nice but I can't figure how to use them nicely with DDD.
Given a service "employees" who is the master of the Employee datas, it is a crud over a couple of simple values (first and lastname, birthdate, address).
My new app, should track the trainings offered to those employees. So I have the concept of Participant, a Participant has the same values as an Employee plus a list of trainings and a skill.
We can suppose that the "trainings" applications has a database with a table of participants that contains a participant_id, skill and one employee_id used to retrieve the first and lastname.
Am I correct ?
But now, which component may I use to call the "employees" service ? Is it the ParticipantRepository so that when I get a participant I have is names. Or is it the application service who complete the Participant datas before using them. Or may I explicitly call the employees service when needed ?
Thanks a lot.
In your training application (I mean in the domain of your application) the concept of an employee might not exist as other than an external reference. As you correctly said, that will be a Participant.
I understand that you need to get some data from the employee service to populate the participant. I can think of few options.
1) ParticipantRepository builds a Participant, which is an aggregate root, some of that data might be in a PersonalDetails value object. This value object is constructed by calling the employee app. This approach is easy, but might not be the best. This is the approach you mentioned, where the ParticipantRepository calls an interface PersonalDetailsService and the implementation of that interface does the actual call to the Employee service. In this way, your domain has no idea that is dealing with employees, as it only sees PersonalDetails.
2) Eventual consistency by replicating data from the employee service: If the employee service can send a notification when an employee is updated (e.g. via messaging) you can listen to those events and have a read only copy of the data. The benefit of this is that your app will work even if the employee service goes down. The problem is that you might need to build something to re-send data that might have got lost.
Both of these approaches are explained quite well in the book Implementing Domain-Driven Design

Resources