Azure ServiceBus PeekLock stopping the peeking client being sent more messages

the system I’m developing has multiple clients sending requests to 3 queues with multiple servers servicing one or more of these using a ServiceBusProcessor (not a ServiceBusReceiver) in PeekLock mode, AutoComplete false, prefetch and max concurrent 1.

Each server can take anywhere from ~1 to ~10 seconds to process a request, and can only ever process one at a time (it’s a heavy number crunching thing that runs as many threads as the server can handle, so running >1 would kill performance).

As such, I want each server to receive a message via the OnReceived event handler, process it and not get any other requests until I have completed (or abandoned) the one that is being processed.

I get a message via the event handler, process it and complete it; I am using PeekLock as I thought that would stop the processor getting more messages until it had finished, but that seems not to be the case. There’s no real need to abandon messages or explicitly complete them, am only using PeekLock as I though I needed to do that to force requests to come one-by-one.

This was simple with Rabbit but I’ve recently switched over to using ServiceBus, and while it works OK in general, I find servers that have locked and are processing a message are sometimes getting another message, and another, before I have completed (or abandoned) the one that’s being processed.

If I drop down to just one server to make the problem more obvious, each new message is immediately sent on to the server as it’s queued – but I want the messages to back up in the queue and possibly be auto DLQ’d if the server can’t handle them in time.

I can’t find any definitive statement in the documentation or elsewhere to say that once a server had peek-locked a message, the processor won’t get another message, and can’t find any option/setting to make that happen, quite possibly because it’s not something that a ServiceBusProcesser can do but I wish I could find a definitive statement about it somewhere.

Right now, I’m doing what seems very much like a hack; I am calling StopProcessing() on the queue on receipt of a message and StartProcessing() when the server is ready to process another, which does work but feels very wrong – and what if another message comes in just before I call StopProcessing() – so I have a bool _isProcessing that abandons the message if that happens… and then what if… so maybe adding a lock() on the test/set of _isProcessing… but I’m very conscious of wandering down a smelly code path that I really don’t want to.

As-is, I might as well use ReceiveAndDelete if I have to manually pause listening anyway !

It might well be that the correct solution is to use a ServiceBusReceiver instead of a ServiceBusProcesser, but would prefer not to have to rework it if there is a way to have this one-by-one requirement handled by ServiceBus, rather than me hacking in clumsy workarounds.

Am I asking ServiceBusProcessor to do something is just isn’t designed for, or missing some setting/option, or misunderstanding something fundamental?

The other way to put it is, should I just change over to using a ServiceBusReceiver instead? Then I’d process the message and when I’m done, call the interface to receive another, simple, but with several other components using other queues I built a generic ‘ServiceBusService’ that handles all this and it only uses ServiceBusProcesser – other queues are either used in ReceiveAndDelete mode, or are happy to handle multiple requests in parallel – it’s just this one component that absolutely needs to process one request only at a time and seems a shame to add the ServiceBusReceiver ‘pattern’ to my service class just for this case, unless I need to.

New contributor

Chris 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