如何在 Eventhub 中配置 Producer.close() [英] How to configure Producer.close() in Eventhub

查看:25
本文介绍了如何在 Eventhub 中配置 Producer.close()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是以下场景.我有一个发布事件的事件生产者.我参考了 mircosoft 文档 https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-java-get-started-send

Here is the following scenario. I have a Event Producer which publishes events. I referred the mircosoft document https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-java-get-started-send

根据我的用例,我有一个 bean,它将在我的应用程序开始时创建 eventhubProducerClient 连接.但是,在发送每个事件后调用我的 send 方法(来自上述文档)中的 producer.close().所以,这导致我的生产者关闭,当我想发送下一个事件时,已经有生产者终止的异常.

According to my usecase, I have a bean which would create the eventhubProducerClient connection at start of my application. However , the producer.close() in my send method (from above documentation) is called after each event is sent. So, this leads to close of my producer and when I would like to send the next event, there is already an exception that the producer is terminated.

处理producer.close()的最好方法是什么.我可以让制作人保持开放吗?那不会导致内存泄漏吗?是否有关于如何处理此问题的策略?任何线索都会有所帮助

What is the best way to handle the producer.close (). can I leave the producer open ? Wouldnt that cause a memory leak ? Is there a strategy on how I can handle this ? any lead would be helpful

谢谢

推荐答案

每种事件中心客户端类型都可以安全地缓存并在应用程序的生命周期内用作单例,这是发布事件或发布事件时的最佳实践定期阅读.客户端负责有效管理网络、CPU 和内存使用,努力在不活动期间保持低使用率.需要在客户端上调用 close 以确保正确清理网络资源和其他非托管对象.

Each of the Event Hubs client types is safe to cache and use as a singleton for the lifetime of the application, which is best practice when events are being published or read regularly. The clients are responsible for efficient management of network, CPU, and memory use, working to keep usage low during periods of inactivity. Calling close on a client is required to ensure that network resources and other unmanaged objects are properly cleaned up.

这篇关于如何在 Eventhub 中配置 Producer.close()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆