Why my Spring boot EventHubConsumer has Duplicate consumption issue

I have an EventHubConsumer that consumes data from Azure EventHub. So I have Event Grid Topic that is consuming from external Producer. The event grid topic after consuming from Producer it pushes data to EventHub and I am then consuming from the EventHub in my spring boot application. The consumer is working and I am able to consume events/me ssages and I save them to a database tracker table. The issue I am seeing is that I see duplicates are been processed and saved. The producer is not sending duplicates.

So this is the architecture I have:

Producer: Event Grid Topic: One EventHub consumer (EventHub subscription to event grid): One partition: One consumer group: Spring boot application

I debugged my application and I see that its not my service method processAzureEventHubMessage that is causing the issue because I see that it processes a 1 message at a time and finishes it by saving it to database, and I see “Checkpoint was updated successfully” after each execution of the method when it finishes processing a single message. I don’t know if it’s not checkpointing correctly, and I don’t know why the same message comes again from eventHub to my application, but I set up all my config correctly and I am not sure If something is missing in my config or my code.

Please help if you see any bug in the code that might cause the duplication issue.

My Consumer method:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Bean
public Consumer<Message<String>> consume(){
return message ->{
Checkpointer checkpointer = (Checkpointer) message.getHeaders().get(CHECKPOINTER);
message.getPayload(),
message.getHeaders().get(AzureHeaders.PARTITION_KEY),
message.getHeaders().get(EventHubsHeaders.SEQUENCE_NUMBER),
message.getHeaders().get(EventHubsHeaders.OFFSET),
message.getHeaders().get(EventHubsHeaders.ENQUEUED)
);
try{
processAzureEventHubMessage(message);
checkpointer.success().block();
log.inf("Checkpoit was updated successfully", message.getHeaders().get(EventHubsHeaders.SEQUENCE_NUMBER));
}catch(Exception e){
log.error("Error processing event", e.getMessage());
}
};
}
</code>
<code>@Bean public Consumer<Message<String>> consume(){ return message ->{ Checkpointer checkpointer = (Checkpointer) message.getHeaders().get(CHECKPOINTER); message.getPayload(), message.getHeaders().get(AzureHeaders.PARTITION_KEY), message.getHeaders().get(EventHubsHeaders.SEQUENCE_NUMBER), message.getHeaders().get(EventHubsHeaders.OFFSET), message.getHeaders().get(EventHubsHeaders.ENQUEUED) ); try{ processAzureEventHubMessage(message); checkpointer.success().block(); log.inf("Checkpoit was updated successfully", message.getHeaders().get(EventHubsHeaders.SEQUENCE_NUMBER)); }catch(Exception e){ log.error("Error processing event", e.getMessage()); } }; } </code>
@Bean
public Consumer<Message<String>> consume(){
   return message ->{
    Checkpointer checkpointer = (Checkpointer) message.getHeaders().get(CHECKPOINTER);
        message.getPayload(),
        message.getHeaders().get(AzureHeaders.PARTITION_KEY),
        message.getHeaders().get(EventHubsHeaders.SEQUENCE_NUMBER),
        message.getHeaders().get(EventHubsHeaders.OFFSET),
        message.getHeaders().get(EventHubsHeaders.ENQUEUED)
        );
       try{
          processAzureEventHubMessage(message);
          checkpointer.success().block();
          log.inf("Checkpoit was updated successfully",     message.getHeaders().get(EventHubsHeaders.SEQUENCE_NUMBER));
          
       }catch(Exception e){
          log.error("Error processing event", e.getMessage());
       }
   };
}

My Service method that processes the message do some mapping and save it to a Database table

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public Response processAzureEventHubMessage(Message<String> message){
Response reponse = new Response();
try{
Data data = eventConverter.convertToObject(message.getPayload());
Request request = new Request();
String player_id = data.getEvent().getPaymentEvent().getPlayerId().trim();
String status = data.getEvent().getPlayerEvent().getType().trim().toUpperCase();
// below is just some rest of logic that process the data and send it to database
}
}
return response;
}
</code>
<code>public Response processAzureEventHubMessage(Message<String> message){ Response reponse = new Response(); try{ Data data = eventConverter.convertToObject(message.getPayload()); Request request = new Request(); String player_id = data.getEvent().getPaymentEvent().getPlayerId().trim(); String status = data.getEvent().getPlayerEvent().getType().trim().toUpperCase(); // below is just some rest of logic that process the data and send it to database } } return response; } </code>
public Response processAzureEventHubMessage(Message<String> message){

 Response reponse = new Response();
 try{
   

    Data data = eventConverter.convertToObject(message.getPayload());
    Request request = new Request();

    String player_id = data.getEvent().getPaymentEvent().getPlayerId().trim();
    String status = data.getEvent().getPlayerEvent().getType().trim().toUpperCase();

    // below is just some rest of logic that process the data and send it to database
    }

 }
   return response;
}


My config yaml file for the eventHub Consumer:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>spring:
cloud:
azure:
eventhubs:
connection-string: ......
processor:
checkpointer-store:
account-name: checkpointerstorage
container-name: messages-container
stream:
bindings:
consume-in-o:
destination: my-eventhub
group: my-consumer-group
eventhubs:
bindings:
consume-in-0:
consumer:
checkpoint:
mode: MANUAL
poller:
initial-delay: 50
fixed delay: 1000
function:
destination: consume
</code>
<code>spring: cloud: azure: eventhubs: connection-string: ...... processor: checkpointer-store: account-name: checkpointerstorage container-name: messages-container stream: bindings: consume-in-o: destination: my-eventhub group: my-consumer-group eventhubs: bindings: consume-in-0: consumer: checkpoint: mode: MANUAL poller: initial-delay: 50 fixed delay: 1000 function: destination: consume </code>
spring:
  cloud:
    azure:
      eventhubs:
        connection-string: ......
        processor:
          checkpointer-store:
            account-name: checkpointerstorage
            container-name: messages-container

    stream:
       bindings:
         consume-in-o:
           destination: my-eventhub
           group: my-consumer-group

       eventhubs:
         bindings:
           consume-in-0:
             consumer:
               checkpoint:
                mode: MANUAL
       poller:
         initial-delay: 50
         fixed delay: 1000
    function:
      destination: consume

New contributor

Jawad Timzit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật