If I want to submit a message to a Kafka topic, do I have to create a new producer every time within an activity? I’m assuming there is no way of holding onto singleton objects that have long-running TCP connections.
No, you can create a Kafka producer once per process lifetime. The specific way to pass it to activity depends on the SDK. In most SDKs, this is done by passing it as an argument to an object constructor. This object has methods that implement activities.
I’m using .NET and what is process lifetime? Can you send more info on that?
I’m not sure what terminology .NET uses for lifetimes. Here is a relevant sample.
So how many times is public class MyActivities created by framework? Also there is not Dependency Injection? Seems like the Db client will get created many time.
So how many times is public class MyActivities created by framework?
In that sample, the user instantiates the activity class that lives for the life of the worker, see the adjacent Program.cs
.
Also there is not Dependency Injection?
There is, see this DI sample and read the README for the hosting extension. Like normal .NET DI, scoped/transient activities are instantiated for each execution whereas singleton activities are instantiated once.