Skip to content

Commit

Permalink
修复队列交换信息获取失败导致线程被堵死的问题。 📺
Browse files Browse the repository at this point in the history
  • Loading branch information
PopeyeZhong committed Jan 18, 2025
1 parent 6192d35 commit c632479
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions Zongsoft.Messaging.ZeroMQ/src/ZeroQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,13 @@ private void Initialize()
if(_publisher != null)
return;

//获取网络交换器的发布和订阅端口号
//获取队列交换器的发布和订阅端口号
(_publisherPort, _subscriberPort) = GetPorts(this.ConnectionSettings);

//如果队列交换器的端口信息获取失败则抛出异常
if(_publisherPort == 0 || _subscriberPort == 0)
throw new InvalidOperationException($"Failed to acquire queue exchange information from the '{this.ConnectionSettings.Server}:{this.ConnectionSettings.Port}' server.");

//创建一个发布者套接字
var publisher = new PublisherSocket();

Expand All @@ -224,11 +228,8 @@ private void Initialize()
//发送请求获取交换器端口号
requester.SendFrameEmpty();

//接收返回的请求响应信息
var response = requester.ReceiveFrameString();

//如果响应信息为空则返回失败
if(string.IsNullOrEmpty(response))
//接收返回的请求响应信息,如果获取失败则返回
if(!requester.TryReceiveFrameString(out var response) || string.IsNullOrEmpty(response))
return default;

ushort publisherPort = 0, subscriberPort = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>0.5.3.0</Version>
<Version>0.5.4.0</Version>
<Product>Zongsoft ZeroMQ Library</Product>
<Description>This is a library about the ZeroMQ messaging development.</Description>
<RootNamespace>Zongsoft.Messaging.ZeroMQ</RootNamespace>
Expand Down

0 comments on commit c632479

Please sign in to comment.