Skip to content

Commit

Permalink
Implemented MaxMessages "limiter" for Queue Browsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
GyroGearl00se committed Jun 16, 2024
1 parent 6438d70 commit ff506ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Components/Pages/QueueBrowser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<label>Queue Name</label>
<input @bind="queueName" name="queueName" autocomplete="on" placeholder="Queue Name" />
</div>
<div class="form-group">
<label>Max Messages</label>
<input @bind="maxMessages" type="number" name="maxMessages" min="1" />
</div>
<button class="btn btn-primary" @onclick="BrowseQueueAsync">Browse Queue</button>

<div>
Expand Down Expand Up @@ -140,6 +144,7 @@
private string username;
private string password;
private string queueName;
private int maxMessages = 50;
private bool sslVerify = true;
private bool useTcps = true;
private List<MessageDetails> messages = new List<MessageDetails>();
Expand All @@ -162,7 +167,7 @@
{
string formattedHost = FormatHost(host, useTcps);
isBrowsing = true;
messages = await QueueBrowserService.BrowseQueueAsync(formattedHost, vpnName, username, password, queueName, sslVerify);
messages = await QueueBrowserService.BrowseQueueAsync(formattedHost, vpnName, username, password, queueName, sslVerify, maxMessages);
Logger.LogInformation("Messages retrieved: {count}", messages.Count);
}
catch (SolaceSystems.Solclient.Messaging.OperationErrorException ex)
Expand Down
6 changes: 4 additions & 2 deletions Services/QueueBrowserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void Disconnect()



public async Task<List<MessageDetails>> BrowseQueueAsync(string host, string vpnName, string username, string password, string queueName, bool sslVerify)
public async Task<List<MessageDetails>> BrowseQueueAsync(string host, string vpnName, string username, string password, string queueName, bool sslVerify, int maxMessages)
{
_logger.LogInformation("Queue Browsing started.");
List<MessageDetails> messages = new List<MessageDetails>();
Expand Down Expand Up @@ -91,7 +91,8 @@ public async Task<List<MessageDetails>> BrowseQueueAsync(string host, string vpn
using (IBrowser browser = _session.CreateBrowser(queue, browserProps))
{
IMessage message;
while ((message = await Task.Run(() => browser.GetNext())) != null)
int messageCount = 0;
while ((message = await Task.Run(() => browser.GetNext())) != null && messageCount < maxMessages)
{
//_logger.LogInformation("Message received: {message}", Encoding.UTF8.GetString(message.BinaryAttachment));
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(message.SenderTimestamp);
Expand Down Expand Up @@ -129,6 +130,7 @@ public async Task<List<MessageDetails>> BrowseQueueAsync(string host, string vpn
UserProperties = keyValuePairs,
DeliveryMode = message.DeliveryMode.ToString()
});
messageCount++;
}
}
}
Expand Down

0 comments on commit ff506ec

Please sign in to comment.