I extended the sample java project with some specific changes. I have a lot of different microservices, for this example, you can think about back-service and bonus-service.
Bank service will do withdraw and deposit, after that bonus-service will check available bonuses.
Because of that, I created 2 different activity and activity-impl.
Workflow implementation like this.
I have 2 worker clients, one of them for bank service and another one is bonus service. But after initiating a workflow, sometimes check bonus method not found error I got, sometimes withdraw method not found method error I got.
Can you explain to me, How can I create a workflow between microservices? I saw a lot of samples but all of them were in the same package or one activity method they use.
Regarding the code, by default an activity type is the name of the activity method with first letter upper-case, so the value of WITHDRAW that you put as key in per-activity options should be “Withdraw” (with upper case W).
I have 2 worker clients, one of them for bank service and another one is bonus service
Are both polling the same task queue? Are they in the same process? If you don’t set taskQueue in activity options, activity will run on the same task queue as what you specified in WorkflowOptions for this workflow (in client code), so in your case they would run on the same.
But after initiating a workflow, sometimes check bonus method not found error I got, sometimes withdraw method not found method error I got.
I think you need to have each activity worker on a separate task queue and set it in the ActivityOptions in your workflow code. Can you show your code where you create workers and register workflow impl and activities?
Thank you very much for your quick response, I shared the code in a repository on GitHub. You can check it. My thought is to call multiple microservices in a workflow. Because a workflow is the whole of the processes that different microservices will do. My implementation may be wrong.
I don’t think that “BonusWorker” needs to register the workflow impl:
as it hosts only the activity that your are invoking from the workflow in “banking service”.
You do not need to share “activity-lib” between the two services, each service should contain only what it needs imo. You could use untyped stub in your banking-service to invoke an activity in bonus-service.
See the polyglot samples here and here which could give you ideas, and video here if it helps.
Just one more thing to add, in MoneyTransferWorkflowImpl:
a) It’s best to not limit retries using setMaximumAttempts but to use ScheduleToClose activity timeout, see activity timeouts video here.
b) You can specify per-activity options via WorkflowImplementationOptions which might help, see sample here.