Skip to content

Commit 513ff95

Browse files
committed
* Add license headers
* Enable publisher confirms
1 parent 5296d44 commit 513ff95

File tree

2 files changed

+80
-6
lines changed

2 files changed

+80
-6
lines changed

projects/Test/Applications/CreateChannel/Program.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
using System;
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 2.0.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// https://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v2.0:
23+
//
24+
//---------------------------------------------------------------------------
25+
// This Source Code Form is subject to the terms of the Mozilla Public
26+
// License, v. 2.0. If a copy of the MPL was not distributed with this
27+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
28+
//
29+
// Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
30+
//---------------------------------------------------------------------------
31+
32+
using System;
233
using System.Diagnostics;
334
using System.Threading;
435
using System.Threading.Tasks;

projects/Test/Applications/GH-1647/Program.cs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 2.0.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// https://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v2.0:
23+
//
24+
//---------------------------------------------------------------------------
25+
// This Source Code Form is subject to the terms of the Mozilla Public
26+
// License, v. 2.0. If a copy of the MPL was not distributed with this
27+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
28+
//
29+
// Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
30+
//---------------------------------------------------------------------------
31+
32+
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
233
using System.Text;
334
using RabbitMQ.Client;
435

@@ -9,18 +40,30 @@
940
Password = "guest"
1041
};
1142

43+
var channelOptions = new CreateChannelOptions
44+
{
45+
PublisherConfirmationsEnabled = true,
46+
PublisherConfirmationTrackingEnabled = true
47+
};
48+
1249
var props = new BasicProperties();
1350
byte[] msg = Encoding.UTF8.GetBytes("test");
1451
await using var connection = await connectionFactory.CreateConnectionAsync();
1552
for (int i = 0; i < 300; i++)
1653
{
1754
try
1855
{
19-
await using var channel = await connection.CreateChannelAsync(); // New channel for each message
56+
await using var channel = await connection.CreateChannelAsync(channelOptions); // New channel for each message
2057
await Task.Delay(1000);
21-
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: string.Empty,
22-
mandatory: false, basicProperties: props, body: msg);
23-
Console.WriteLine($"Sent message {i}");
58+
if (await channel.BasicPublishAsync(exchange: string.Empty, routingKey: string.Empty,
59+
mandatory: false, basicProperties: props, body: msg))
60+
{
61+
Console.WriteLine($"Sent message {i}");
62+
}
63+
else
64+
{
65+
Console.Error.WriteLine($"[ERROR] message {i} not acked!");
66+
}
2467
}
2568
catch (Exception ex)
2669
{

0 commit comments

Comments
 (0)