Hi all!
I would like to create a microservices architecture based on Springboot + RabbitMQ + Temporal. The idea is to create a Temporal microservice that, during the application startup phase, records the workers that will be used by the entire ecosystem. Subsequently, in the same microservice, all application workflows are created and launched.
These workflows will refer to activities that will have the task of writing to the queues and delegating the business logic to other microservices.
When the microservices finish their work, they write on another topic that will be read by the Temporal microservice and will trigger the next methods present in the workflow
The architectural scheme that i want create is like this:
-
Temporal Microservice:
- Register workers
- Manage workflows and activities
- Write/read only messages and params to different topic managed by RabbitMQ
-
N Microservices: contains some business logic and write result on specific topic
An example (with 3 microservices) can be represented like this:
-
Workflow Interface
@WorkflowMethod void workflowExecution(); @SignalMethod void firstEnded(Object someResult); @SignalMethod void secondEnded(Object someResult);
-
Workflow Implementation
ActivityOptions options = ActivityOptions.newBuilder() .setScheduleToCloseTimeout(Duration.ofSeconds(30)) .build(); private final MyActivity activity = Workflow.newActivityStub(MyActivity.class, options); private boolean firstEnded, secondEnded; private Object someResult; @Override public void workflowExecution() { while (true) { //write in a RabbitMQ topic, a microservice listener execute the business logic and then write on another topic (called like firstTopic) Async.function(activity::callFirstMethod, someResult); Workflow.await(() -> firstEnded); //write in a RabbitMQ topic, a microservice listener execute the business logic and then write on another topic (called like secondTopic) Async.function(activity::callSecondMethod, someResult); Workflow.await(() -> secondEnded); Async.function(activity::callThirdMethod, someResult); } } @Override public void firstEnded(Object someResult) { this.someResult = someResult; this.firstEnded= true; } @Override public void secondEnded(Object someResult) { this.someResult = someResult; this.secondEnded = true; }
-
RabbitMQ Listener
Define TopicExchange
private MyWorkflow wf; @PostConstruct public attachOnWorkflow() { WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(); WorkflowClient client = WorkflowClient.newInstance(service); WorkflowOptions options = WorkflowOptions.newBuilder() .setTaskQueue("MY_WORKFLOW_TASK_QUEUE") .setWorkflowId("MyWorkflow") .build(); wf = client.newWorkflowStub(MyWorkflow.class, options); } public listenerOnFirstTopic(Object someResult) { wf.firstEnded(someResult); } public listenerOnSecondTopic(Object someResult) { wf.secondEnded(someResult); }
Is the structure correct? Any suggestions on how to improve it, if is correct?
Thanks in advance!