microservices – How to make consumer idempotent when publisher publishes “at least once”?

I’m trying to implement microservices and I’m still super new to the subject, but, I was able to answer most of questions.

However, one of the questions that I can’t come up with a good solution to is how do I make my consumer idempotent when my publisher publishes at least once?

Graph A

What happens without making Consumer idempotent:

Our consumer receives Event A multiple times, and Event A is asking to pay X dollar to User A, without handling this correctly, we’ve paid User A 3 * X times.

Possible solution

What I’ve come up with is this solution:

We create an Events table in Service A (publisher), we create an entity with an id and serviceName (in this case serviceA) inside Events table, then we proceed to publish the event.

In Service B (consumer), we create a ReceivedEvents table, which holds both eventId and serviceName as primary key, this way, whenever we have a new event, we will first check if the event is inside ReceivedEvents, if not, we proceed to complete the task.

Is this approach good enough? Is there an alternative to this approach?