-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
165 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace ActiveMQ.Artemis.Core.Client.Exceptions; | ||
|
||
public class ActiveMQException : Exception | ||
{ | ||
public ActiveMQException(int code, string message) : base(message) | ||
{ | ||
// TODO: Handle Exception Code as Exception Type | ||
} | ||
} |
28 changes: 16 additions & 12 deletions
28
src/ArtemisNetCoreClient/Framing/ActiveMQExceptionMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
using System.Diagnostics; | ||
|
||
namespace ActiveMQ.Artemis.Core.Client.Framing; | ||
|
||
internal class ActiveMQExceptionMessage : Packet | ||
internal readonly struct ActiveMQExceptionMessage : IIncomingPacket | ||
{ | ||
public const byte Type = 20; | ||
|
||
public int Code { get; private set; } | ||
public string? Message { get; set; } | ||
public readonly int Code; | ||
public readonly string? Message; | ||
public readonly long CorrelationId; | ||
|
||
public virtual void Encode(ByteBuffer buffer) | ||
{ | ||
} | ||
|
||
public virtual void Decode(ByteBuffer buffer) | ||
public ActiveMQExceptionMessage(ReadOnlySpan<byte> buffer) | ||
{ | ||
Code = buffer.ReadInt(); | ||
Message = buffer.ReadNullableString(); | ||
var readBytes = 0; | ||
readBytes += ArtemisBinaryConverter.ReadInt32(buffer, out Code); | ||
readBytes += ArtemisBinaryConverter.ReadNullableString(buffer[readBytes..], out Message); | ||
if (buffer.Length - readBytes >= sizeof(long)) | ||
{ | ||
readBytes += ArtemisBinaryConverter.ReadInt64(buffer[readBytes..], out CorrelationId); | ||
} | ||
|
||
Debug.Assert(readBytes == buffer.Length, $"Expected to read {buffer.Length} bytes but got {readBytes}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using ActiveMQ.Artemis.Core.Client.Framing; | ||
using ActiveMQ.Artemis.Core.Client.Tests.Utils; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace ActiveMQ.Artemis.Core.Client.Tests; | ||
|
||
public class MessagePropertiesSpec(ITestOutputHelper testOutputHelper) | ||
{ | ||
[Fact] | ||
public async Task Should_send_and_receive_message_with_properties() | ||
{ | ||
// Arrange | ||
await using var testFixture = await TestFixture.CreateAsync(testOutputHelper); | ||
await using var connection = await testFixture.CreateConnectionAsync(); | ||
await using var session = await connection.CreateSessionAsync(); | ||
|
||
var addressName = Guid.NewGuid().ToString(); | ||
await session.CreateAddressAsync(addressName, new [] { RoutingType.Multicast }, testFixture.CancellationToken); | ||
await using var producer = await session.CreateProducerAsync(new ProducerConfiguration | ||
{ | ||
Address = addressName | ||
}, testFixture.CancellationToken); | ||
// create queue | ||
var queueName = Guid.NewGuid().ToString(); | ||
await session.CreateQueueAsync(new QueueConfiguration | ||
{ | ||
Address = addressName, | ||
RoutingType = RoutingType.Multicast, | ||
Name = queueName | ||
}, testFixture.CancellationToken); | ||
|
||
await using var consumer = await session.CreateConsumerAsync(new ConsumerConfiguration | ||
{ | ||
QueueName = queueName, | ||
}, testFixture.CancellationToken); | ||
|
||
// Act | ||
await producer.SendMessageAsync(new Message | ||
{ | ||
Body = "test_payload"u8.ToArray(), | ||
Headers = new Headers | ||
{ | ||
Address = addressName | ||
}, | ||
Properties = new Dictionary<string, object?> | ||
{ | ||
["null_property"] = null, | ||
["bool_property_true"] = true, | ||
["bool_property_false"] = false, | ||
["byte_property"] = (byte)42, | ||
["bytes_property"] = new byte[] { 1, 2, 3 }, | ||
["short_property"] = (short)42, | ||
["int_property"] = 43, | ||
["long_property"] = 44L, | ||
["float_property"] = 45.1F, | ||
["double_property"] = 46.2D, | ||
["string_property"] = "string_value", | ||
["char_property"] = 'c', | ||
} | ||
}, testFixture.CancellationToken); | ||
|
||
|
||
var receivedMessage = await consumer.ReceiveMessageAsync(testFixture.CancellationToken); | ||
|
||
// Assert | ||
Assert.NotNull(receivedMessage); | ||
Assert.Equal(12, receivedMessage.Properties.Count); | ||
Assert.Null(receivedMessage.Properties["null_property"]); | ||
Assert.True((bool)receivedMessage.Properties["bool_property_true"]!); | ||
Assert.False((bool)receivedMessage.Properties["bool_property_false"]!); | ||
Assert.Equal((byte)42, (byte)receivedMessage.Properties["byte_property"]!); | ||
Assert.Equal([1, 2, 3], (byte[])receivedMessage.Properties["bytes_property"]!); | ||
Assert.Equal((short)42, (short)receivedMessage.Properties["short_property"]!); | ||
Assert.Equal(43, (int)receivedMessage.Properties["int_property"]!); | ||
Assert.Equal(44L, (long)receivedMessage.Properties["long_property"]!); | ||
Assert.Equal(45.1F, (float)receivedMessage.Properties["float_property"]!); | ||
Assert.Equal(46.2D, (double)receivedMessage.Properties["double_property"]!); | ||
Assert.Equal("string_value", (string)receivedMessage.Properties["string_property"]!); | ||
Assert.Equal('c', (char)receivedMessage.Properties["char_property"]!); | ||
} | ||
} |