# Register activities dynamically with worker

**URL:** <https://community.temporal.io/t/register-activities-dynamically-with-worker/4859>\
**Category:** Community Support\
**Tags:** go-sdk\
**Created:** [June 2, 2022, 8:48am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859 "2022-06-02T08:48:38Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![swapnilk26](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@swapnilk26](https://community.temporal.io/u/swapnilk26)\
**Post date:** [June 2, 2022, 8:48am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/1 "2022-06-02T08:48:38Z")

</div>

My worker is running ( I have registered 1 workflow and 3 activities before starting worker) Now while executing workflow I want to create a activity at runtime and want it to be processed by the same worker ( but since i am spawning the activity at runtime I havent registered this activity with worker before starting ) So can the same worker process the newly spawnned activity?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [June 2, 2022, 3:01pm UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/2 "2022-06-02T15:01:51Z")

</div>

Which SDK are yo using?

---

<div class="post-metadata">

**Author:** ![swapnilk26](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@swapnilk26](https://community.temporal.io/u/swapnilk26)\
**Post date:** [June 5, 2022, 4:38am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/3 "2022-06-05T04:38:10Z")

</div>

I am using golang SDK

---

<div class="post-metadata">

**Author:** ![pvs\_praneeth](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pvs_praneeth/32/2116_2.png) [@pvs\_praneeth](https://community.temporal.io/u/pvs_praneeth)\
**Post date:** [June 7, 2022, 12:23am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/4 "2022-06-07T00:23:00Z")

</div>

Is there a way to achieve this @tihomir. I am using java SDK

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [June 7, 2022, 1:01am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/5 "2022-06-07T01:01:01Z")

</div>

For Java you can use DynamicActivity, sample [here](https://github.com/temporalio/samples-java/blob/main/src/main/java/io/temporal/samples/hello/HelloDynamic.java#L73).  
I don’t think equivalent exists in Go SDK at this time, see open issue [here](https://github.com/temporalio/sdk-go/issues/543).

---

<div class="post-metadata">

**Author:** ![pvs\_praneeth](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pvs_praneeth/32/2116_2.png) [@pvs\_praneeth](https://community.temporal.io/u/pvs_praneeth)\
**Post date:** [June 7, 2022, 1:15am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/6 "2022-06-07T01:15:27Z")

</div>

For reference, let’s say i have activity type 1, which makes a **HTTP call** and I have an another activity which performs **sqlquery** that I have defined after the worker has started, _How do I make the dynamic activity execute these activity types depending on the input type that is passed_?

I am using the dynamic dsl workflow example that you have [shared](https://community.temporal.io/t/looking-for-info-to-create-an-event-from-workflow-activity-using-serverless-workflow-dsl/4881/5) in the previous discussion as example. Looking to update that example with dynamic activities execution.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [June 7, 2022, 1:19am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/7 "2022-06-07T01:19:58Z")

</div>

Similar to DynamicWorkflow, you can register only a single activity impl that implements DynamicActivity (per worker).  
Yes, you could get the activity type via:  
`Activity.getExecutionContext().getInfo().getActivityType();`  
and perform different operations per type.

---

<div class="post-metadata">

**Author:** ![pvs\_praneeth](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pvs_praneeth/32/2116_2.png) [@pvs\_praneeth](https://community.temporal.io/u/pvs_praneeth)\
**Post date:** [June 7, 2022, 1:27am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/8 "2022-06-07T01:27:57Z")

</div>

Is this the way(or similar) to perform different operations based on the type?

```java
@Override
    public Object execute(EncodedValues args) {
        String activityType = Activity.getExecutionContext().getInfo().getActivityType();
        log.info("Executing dynamic activity: {}", activityType);
        try {
            if (activityType = "httpcall") {
                //// Logic to execute the http activity
            }else if(activityType = "sqlquery"){
                //// Logic to execute the sql activity
            }else {
                return null;
            }
        } catch (Exception e) {
            return null;
        }
    }

```

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [June 7, 2022, 1:42am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/9 "2022-06-07T01:42:44Z")

</div>

Yes, that should be ok, probably should use `.equals` or `==` for String comparison.

---

<div class="post-metadata">

**Author:** ![pvs\_praneeth](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pvs_praneeth/32/2116_2.png) [@pvs\_praneeth](https://community.temporal.io/u/pvs_praneeth)\
**Post date:** [June 7, 2022, 1:45am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/10 "2022-06-07T01:45:59Z")

</div>

Got it. But the problem that I am looking at is if I add a new activityType later(called **fetchData** ), after the worker has started, is there a way to call that activity using temporal without modifying the DynamicActivity execute function?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [June 7, 2022, 1:51am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/11 "2022-06-07T01:51:59Z")

</div>

> is there a way to call that activity using temporal without modifying the DynamicActivity execute function

Where is the code that executes the fetch activity? You can change activity code without breaking workflow determinism, would have to restart your workers tho for changes to be picked up.

---

<div class="post-metadata">

**Author:** ![pvs\_praneeth](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pvs_praneeth/32/2116_2.png) [@pvs\_praneeth](https://community.temporal.io/u/pvs_praneeth)\
**Post date:** [June 7, 2022, 1:55am UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/12 "2022-06-07T01:55:00Z")

</div>

Checking for an option to load the new code/jar dynamically into the application jvm.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [June 7, 2022, 1:21pm UTC](https://community.temporal.io/t/register-activities-dynamically-with-worker/4859/13 "2022-06-07T13:21:24Z")

</div>

> Checking for an option to load the new code/jar dynamically into the application jvm.

I think this is dependent on your impl, frameworks used, deployment strategies etc, not specifically with Temporal itself. Maybe there are some others in community that have done something similar that could share.
