|
8 | 8 | using System.Text;
|
9 | 9 | using System.Threading;
|
10 | 10 | using System.Threading.Tasks;
|
| 11 | +using Amqp; |
11 | 12 | using RabbitMQ.Client;
|
12 | 13 | using RabbitMQ.Client.Events;
|
13 | 14 | using RabbitMQ.Stream.Client;
|
14 | 15 | using RabbitMQ.Stream.Client.AMQP;
|
15 | 16 | using RabbitMQ.Stream.Client.Reliable;
|
16 | 17 | using Xunit.Abstractions;
|
| 18 | +using ConnectionFactory = RabbitMQ.Client.ConnectionFactory; |
| 19 | +using Message = RabbitMQ.Stream.Client.Message; |
17 | 20 |
|
18 | 21 | namespace Tests;
|
19 | 22 |
|
@@ -102,8 +105,7 @@ public async void Amqp10ShouldReadTheAmqp019Properties()
|
102 | 105 | properties.UserId = "guest";
|
103 | 106 | properties.Headers = new Dictionary<string, object>()
|
104 | 107 | {
|
105 |
| - {"stream_key", "stream_value"}, |
106 |
| - {"stream_key4", "Alan Mathison Turing(1912 年 6 月 23 日"}, |
| 108 | + {"stream_key", "stream_value"}, {"stream_key4", "Alan Mathison Turing(1912 年 6 月 23 日"}, |
107 | 109 | };
|
108 | 110 | channel.BasicPublish("", stream, properties, Encoding.ASCII.GetBytes("FromAMQP"));
|
109 | 111 | var tcs = new TaskCompletionSource<Message>();
|
@@ -170,20 +172,20 @@ await producer.Send(new Message(Encoding.ASCII.GetBytes($"FromStream{i}"))
|
170 | 172 | {
|
171 | 173 | Properties = new Properties()
|
172 | 174 | {
|
173 |
| - MessageId = $"Alan Mathison Turing(1912 年 6 月 23 日 - 1954 年 6 月 7 日)是英国数学家、计算机科学家、逻辑学家、密码分析家、哲学家和理论生物学家。 [6] 图灵在理论计算机科学的发展中具有很大的影响力,用图灵机提供了算法和计算概念的形式化,可以被认为是通用计算机的模型。[7][8][9] 他被广泛认为是理论计算机科学和人工智能之父{i}", |
| 175 | + MessageId = |
| 176 | + $"Alan Mathison Turing(1912 年 6 月 23 日 - 1954 年 6 月 7 日)是英国数学家、计算机科学家、逻辑学家、密码分析家、哲学家和理论生物学家。 [6] 图灵在理论计算机科学的发展中具有很大的影响力,用图灵机提供了算法和计算概念的形式化,可以被认为是通用计算机的模型。[7][8][9] 他被广泛认为是理论计算机科学和人工智能之父{i}", |
174 | 177 | CorrelationId = "10000_00000",
|
175 | 178 | ContentType = "text/plain",
|
176 | 179 | ContentEncoding = "utf-8",
|
177 | 180 | UserId = Encoding.ASCII.GetBytes("MY_USER_ID"),
|
178 | 181 | GroupSequence = 601,
|
179 | 182 | ReplyToGroupId = "ReplyToGroupId",
|
180 | 183 | GroupId = "GroupId",
|
181 |
| - |
182 | 184 | },
|
183 | 185 | ApplicationProperties = new ApplicationProperties()
|
184 | 186 | {
|
185 | 187 | {"stream_key", "stream_value"},
|
186 |
| - {"stream_key2", 100}, |
| 188 | + {"stream_key2", 100}, |
187 | 189 | {"stream_key3", 10_000_009},
|
188 | 190 | {"stream_key4", "Alan Mathison Turing(1912 年 6 月 23 日"},
|
189 | 191 | }
|
@@ -258,4 +260,59 @@ public async void Amqp10ShouldReadTheAmqp019Properties1000Messages()
|
258 | 260 | await system.DeleteStream(stream);
|
259 | 261 | await system.Close();
|
260 | 262 | }
|
| 263 | + |
| 264 | + /// <summary> |
| 265 | + /// In this test se send 1 message using the Amqp10 Producer https://github.com/Azure/amqpnetlite to |
| 266 | + /// a stream and then we read it using. |
| 267 | + /// See https://github.com/rabbitmq/rabbitmq-stream-dotnet-client/pull/217 |
| 268 | + /// </summary> |
| 269 | + [Fact] |
| 270 | + public async void StreamShouldReadTheAmqp10PropertiesMessages() |
| 271 | + { |
| 272 | + SystemUtils.InitStreamSystemWithRandomStream(out var system, out var stream); |
| 273 | + |
| 274 | + var address = new Address("amqp://guest:guest@localhost:5672"); |
| 275 | + var connection = new Amqp.Connection(address); |
| 276 | + var session = new Session(connection); |
| 277 | + |
| 278 | + var message = new Amqp.Message("msg from amqp 1.0"); |
| 279 | + message.Properties = new Amqp.Framing.Properties() |
| 280 | + { |
| 281 | + MessageId = "1", |
| 282 | + Subject = "test", |
| 283 | + ContentType = "text/plain" |
| 284 | + }; |
| 285 | + message.ApplicationProperties = new Amqp.Framing.ApplicationProperties() |
| 286 | + { |
| 287 | + Map = { { "key1", "value1" }, { "key2", 2 } } |
| 288 | + }; |
| 289 | + |
| 290 | + var sender = new SenderLink(session, "mixing", $"/amq/queue/{stream}"); |
| 291 | + await sender.SendAsync(message); |
| 292 | + await sender.CloseAsync(); |
| 293 | + await session.CloseAsync(); |
| 294 | + await connection.CloseAsync(); |
| 295 | + |
| 296 | + var tcs = new TaskCompletionSource<Message>(); |
| 297 | + var consumer = await Consumer.Create(new ConsumerConfig(system, stream) |
| 298 | + { |
| 299 | + OffsetSpec = new OffsetTypeFirst(), |
| 300 | + MessageHandler = async (_, _, _, streamMessage) => |
| 301 | + { |
| 302 | + tcs.SetResult(streamMessage); |
| 303 | + await Task.CompletedTask; |
| 304 | + } |
| 305 | + }); |
| 306 | + |
| 307 | + new Utils<Message>(_testOutputHelper).WaitUntilTaskCompletes(tcs); |
| 308 | + var result = tcs.Task.Result; |
| 309 | + // Why do we need result.Data.Contents.ToArray()[5..]? |
| 310 | + // Because of https://github.com/rabbitmq/rabbitmq-server/issues/6937 |
| 311 | + // When it will be fixed we can remove the [5..] |
| 312 | + // For the moment we leave it as it is because it is not a problem for the client |
| 313 | + Assert.Equal("msg from amqp 1.0", Encoding.UTF8.GetString(result.Data.Contents.ToArray()[5..])); |
| 314 | + await consumer.Close(); |
| 315 | + await system.DeleteStream(stream); |
| 316 | + await system.Close(); |
| 317 | + } |
261 | 318 | }
|
0 commit comments