|
1 | 1 | using DaJet.Data; |
2 | 2 | using DaJet.Scripting.Model; |
| 3 | +using Npgsql.Replication; |
3 | 4 | using RabbitMQ.Client; |
4 | 5 | using RabbitMQ.Client.Events; |
5 | 6 | using System.Buffers; |
@@ -61,6 +62,66 @@ public Producer(in ScriptScope scope) |
61 | 62 | private string VirtualHost { get; set; } = "/"; |
62 | 63 | private string UserName { get; set; } = "guest"; |
63 | 64 | private string Password { get; set; } = "guest"; |
| 65 | + private TimeSpan GetRequestedHeartbeat() |
| 66 | + { |
| 67 | + if (StreamFactory.TryGetOption(in _scope, "RequestedHeartbeat", out object value)) |
| 68 | + { |
| 69 | + if (value is int seconds) |
| 70 | + { |
| 71 | + return TimeSpan.FromSeconds(seconds); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + return TimeSpan.FromSeconds(60); |
| 76 | + } |
| 77 | + private bool GetAutomaticRecoveryEnabled() |
| 78 | + { |
| 79 | + if (StreamFactory.TryGetOption(in _scope, "AutomaticRecoveryEnabled", out object value)) |
| 80 | + { |
| 81 | + if (value is bool boolean) |
| 82 | + { |
| 83 | + return boolean; |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + return true; |
| 88 | + } |
| 89 | + private TimeSpan GetNetworkRecoveryInterval() |
| 90 | + { |
| 91 | + if (StreamFactory.TryGetOption(in _scope, "NetworkRecoveryInterval", out object value)) |
| 92 | + { |
| 93 | + if (value is int seconds) |
| 94 | + { |
| 95 | + return TimeSpan.FromSeconds(seconds); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + return TimeSpan.FromSeconds(5); |
| 100 | + } |
| 101 | + private TimeSpan GetContinuationTimeout() |
| 102 | + { |
| 103 | + if (StreamFactory.TryGetOption(in _scope, "ContinuationTimeout", out object value)) |
| 104 | + { |
| 105 | + if (value is int seconds) |
| 106 | + { |
| 107 | + return TimeSpan.FromSeconds(seconds); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + return TimeSpan.FromSeconds(30); |
| 112 | + } |
| 113 | + private TimeSpan GetRequestedConnectionTimeout() |
| 114 | + { |
| 115 | + if (StreamFactory.TryGetOption(in _scope, "RequestedConnectionTimeout", out object value)) |
| 116 | + { |
| 117 | + if (value is int seconds) |
| 118 | + { |
| 119 | + return TimeSpan.FromSeconds(seconds); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + return TimeSpan.FromSeconds(30); |
| 124 | + } |
64 | 125 | #endregion |
65 | 126 |
|
66 | 127 | #region "MESSAGE OPTIONS AND VALUES" |
@@ -291,7 +352,12 @@ private void InitializeConnection() |
291 | 352 | Port = HostPort, |
292 | 353 | VirtualHost = VirtualHost, |
293 | 354 | UserName = UserName, |
294 | | - Password = Password |
| 355 | + Password = Password, |
| 356 | + RequestedHeartbeat = GetRequestedHeartbeat(), |
| 357 | + ContinuationTimeout = GetContinuationTimeout(), |
| 358 | + RequestedConnectionTimeout = GetRequestedConnectionTimeout(), |
| 359 | + AutomaticRecoveryEnabled = GetAutomaticRecoveryEnabled(), |
| 360 | + NetworkRecoveryInterval = GetNetworkRecoveryInterval() |
295 | 361 | }; |
296 | 362 |
|
297 | 363 | _connection = factory.CreateConnection(); |
|
0 commit comments