# Workflow Interceptor calling multiple times

**URL:** <https://community.temporal.io/t/workflow-interceptor-calling-multiple-times/16595>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [February 26, 2025, 10:07pm UTC](https://community.temporal.io/t/workflow-interceptor-calling-multiple-times/16595 "2025-02-26T22:07:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mramesh](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@mramesh](https://community.temporal.io/u/mramesh)\
**Post date:** [February 26, 2025, 10:07pm UTC](https://community.temporal.io/t/workflow-interceptor-calling-multiple-times/16595/1 "2025-02-26T22:07:28Z")

</div>

Hello,

I have a use case where we need to publish events whenever a new workflow started and completed.  
We used a class which extends WorkflowInboundCallsInterceptorBase to achieve this

Code as below

public class TestWorkflowInboundInterceptor extends WorkflowInboundCallsInterceptorBase {  
private WorkflowInfo workflowInfo;  
public TestWorkflowInboundInterceptor(WorkflowInboundCallsInterceptor next) {  
super(next);  
this.workflowInfo = Workflow.getInfo();  
}

```
@Override
public WorkflowOutput execute(WorkflowInput input) {
        log.info("Workflow Started");
		//Publish Events saying workflow started 
        WorkflowOutput output = null;
        try {
            output = super.execute(input);
            log.info("Workflow Output Response: {} ", output.getResult());
			//Publish Events saying workflow Completed 
            log.info("Workflow Completed");

        } catch (Exception e) {
            log.info("Workflow Failed");
			//Publish Events saying workflow Failed 
            throw e;
        }
}

```

}

Our code is deployed in multinode architecture ( worker running in 8 nodes) .  
Ideally whenever we send a new WF request i should be seeing only one Workflow Started and one Workflow Completed/Workflow Failed. but we are noticing the  
interceptor is being called multiple times and the events are published multiple times , in some case multiple times in the same node

---

<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:** [February 27, 2025, 2:58am UTC](https://community.temporal.io/t/workflow-interceptor-calling-multiple-times/16595/2 "2025-02-27T02:58:04Z")

</div>

Workflow interceptor should be instantiated once per execution.  
Can you overrider init method, something like

```auto
@Override
public void init(WorkflowOutboundCallsInterceptor outboundCalls) {
  this.workflowInfo = Workflow.getInfo();
  // init workflow outbound interceptor if needed
}

```

and then in execute method log workflow runid from workflowInfo

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [February 27, 2025, 3:13am UTC](https://community.temporal.io/t/workflow-interceptor-calling-multiple-times/16595/3 "2025-02-27T03:13:51Z")

</div>

It is executed in the workflow context. Send events from activities

---

<div class="post-metadata">

**Author:** ![mramesh](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@mramesh](https://community.temporal.io/u/mramesh)\
**Post date:** [February 27, 2025, 4:08pm UTC](https://community.temporal.io/t/workflow-interceptor-calling-multiple-times/16595/4 "2025-02-27T16:08:54Z")

</div>

@Maxim, i need to send events only when workflow initiated and completed. sending from activities wont create duplicate events ?

can you please share sample code.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [February 27, 2025, 8:50pm UTC](https://community.temporal.io/t/workflow-interceptor-calling-multiple-times/16595/5 "2025-02-27T20:50:42Z")

</div>

I don’t understand why sending from activities will create duplicate events? Your activities must be idempotent or if you are OK with data loss you can disable retries.

> [@mramesh](#):
>
> ```auto
> public WorkflowOutput execute(WorkflowInput input) {
> log.info("Workflow Started");
> //Publish Events saying workflow started 
> notificationActivities.notify("started");
> WorkflowOutput output = null;
> try {
> output = super.execute(input);
> log.info("Workflow Output Response: {} ", output.getResult());
> notificationActivities.notify("completed");
> log.info("Workflow Completed");
> 
> } catch (Exception e) {
> log.info("Workflow Failed");
> //Publish Events saying workflow Failed 
> notificationActivities.notify("failed");
> throw e;
> }
> }
> 
> ```
