Microservices architecture implementaiton

Hi,
I have a current micro-srv implementation decoupled by RabbitMq and I want to move to Temporal implementation.
My tech stack is Python and Node currently deployed to a different kind of OS (docker images).
What is not very clear to me is how to register each activity (or several) to different microservices using the Python or Node SDK, without decoupling the code between services (library etc.)
I tried to follow this thread (springboot-microservices) , which seems to try achieving the same goal, but in the end I couldn’t implement it in python or node (maybe because the java api is a bit different).

So for example, here is a very simple workflow:

@workflow.defn
class SayHello:
    @workflow.run
    async def run(self, name: str) -> str:
        hi = await workflow.execute_activity(
            "say_hello", name, schedule_to_close_timeout=timedelta(seconds=5)
        )
        by = await workflow.execute_activity(
            "say_by", name, schedule_to_close_timeout=timedelta(seconds=5)
        )
        return hi + by

And these are the activities:

@activity.defn
async def say_hello(name: str) -> str:
    # I will run on linux server
    return f"Hello, {name}!"


@activity.defn
async def say_by(name: str) -> str:
    # I will run on Unix server
    return f"Byby, {name}!"

So, if I understand correctly I should have in each service a worker that handle different activity:

client = await Client.connect("localhost:7233")

    worker = Worker(
        client,
        task_queue="my-task-queue",
        workflows=[SayHello],
        activities=[say_hello],
    )
    await worker.run()

But when I run it I get the following error:

Activity function say_by is not registered on this worker, available activities: say_hello …

I guess there should be a service that runs only the workflow regardless of the activities (same as the diagram below) what am I missing? will be glad to get directions and the right way to implement it.

Thanks.

Not exactly. Workers should include all workflows/activities that task queue can handle. If you want different activities to run in different workers, you should use different task queues on different workers. Then explicitly set the task queues on execute_activity when you invoke the activity.

Something like this:

Workflow worker:

@workflow.defn
class SayHello:
    @workflow.run
    async def run(self, name: str) -> str:
        # using string as activity name to avoid decoupling
        hi = await workflow.execute_activity(
            "say_hello",
            name,
            task_queue="say-hi-task-queue",
            schedule_to_close_timeout=timedelta(seconds=105),
        )
        # using string as activity name to avoid decoupling
        by = await workflow.execute_activity(
            "say_by",
            name,
            task_queue="say-by-task-queue",
            schedule_to_close_timeout=timedelta(seconds=105),
        )
        return hi + by

async def main():
    # Create client connected to server at the given address
    client = await Client.connect("localhost:7233")

    worker = Worker(
        client,
        task_queue="my-workflow-queue",
        workflows=[SayHello],
        activities=[],
    )
    await worker.run()


Activity worker:


@activity.defn
async def say_hello(name: str) -> str:
    # I will run on linux server
    print("Hello")
    return f"Hello, {name}!"


async def main():
    # Create client connected to server at the given address
    client = await Client.connect("localhost:7233")

    worker = Worker(
        client,
        task_queue="say-hi-task-queue",
        workflows=[SayHello],
        activities=[say_hello],
    )
    await worker.run()```

Mostly, yes. There is a bit of a bug where you execute the workflow on my-workflow-queue but your putting the workflow on say-hi-task-queue. You can choose whether you want to combine the workflows and activities on a task queue or not. But you need to make sure that the worker task queue you put the workflows/activities on is the task queue you are setting when you invoke the workflows/activities.

can you explain why it’s a bug?
The workflow is running on a queue and each activity run on a different queue.
this is the client that start the workflow:

client = await Client.connect("localhost:7233")

    # Execute a workflow
    result = await client.start_workflow(
        "SayHello", "my name", id="my-workflow-id-1", task_queue="my-workflow-queue"
    )

But this says a workflow and activity are running on the same queue:

Leave workflows= off of there if you don’t want workflows on that task queue

Got it … 10X a lot