Skip to content

Commit

Permalink
Support for nodejs azure sb sdk (#12)
Browse files Browse the repository at this point in the history
* support for nodejs azure sb sdk 
  * generate x-opt-locked-until for received messages 
  * generate message-id for received messages 
  * set the correct target address default on attach during CBS auth
* update amqp library
* stabilize rabbitmq in integration tests
  • Loading branch information
piotr-rojek authored Apr 18, 2023
1 parent 8ad36e9 commit 5d7f338
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:

permissions:
contents: write

env:
DOCKERHUBPUSH: ''

jobs:

Expand Down Expand Up @@ -48,15 +51,18 @@ jobs:
username: devopsifyme
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and Push Docker image
- name: Enable Docker Hub Push
if: github.ref == 'refs/heads/main'
run: echo 'DOCKERHUBPUSH=--push' >> "$GITHUB_ENV"

- name: Build and Push Docker image
run: |
export TAG=${{ steps.gitversion.outputs.semVer }}
export TAGMAJOR=${{ steps.gitversion.outputs.major }}
export TAGMAJORMINOR=${{ steps.gitversion.outputs.major }}.${{ steps.gitversion.outputs.minor }}
export TAGMAJORMINORPATCH=${{ steps.gitversion.outputs.majorMinorPatch }}
docker buildx bake -f docker-compose.yml -f docker-compose.amqp1.yml --push
docker buildx bake -f docker-compose.yml -f docker-compose.amqp1.yml ${{ env.DOCKERHUBPUSH }}
- name: Archive build output
run: |
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: "3.9"
services:
rabbit:
image: rabbitmq:3.11.6-management
image: rabbitmq:3-management
user: rabbitmq
ports:
- "15672:15672"
- "5672:5672"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup Label="Packages">
<PackageReference Include="AMQPNetLite" Version="2.4.0" />
<PackageReference Include="AMQPNetLite" Version="2.4.5" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/ServiceBusEmulator.RabbitMq/RabbitMqMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void MapFromRabbit(Message message, ReadOnlyMemory<byte> body, IBasicProp
{
message.MessageAnnotations[new Symbol(key)] = value;
}
message.MessageAnnotations[new Symbol("x-opt-locked-until")] = DateTime.UtcNow.AddDays(1);

message.Properties = new Properties
{
Expand Down Expand Up @@ -100,7 +101,7 @@ public byte[] MapToRabbit(IBasicProperties prop, Message rMessage)
DateTime creationTime = rProperties.CreationTime == DateTime.MinValue ? DateTime.UtcNow : rProperties.CreationTime;

prop.ReplyTo = rProperties.ReplyTo;
prop.MessageId = rProperties.MessageId;
prop.MessageId = rProperties.MessageId ?? Guid.NewGuid().ToString();
prop.CorrelationId = rProperties.CorrelationId;
prop.ContentType = rProperties.ContentType;
prop.ContentEncoding = rProperties.ContentEncoding;
Expand Down
7 changes: 7 additions & 0 deletions src/ServiceBusEmulator/ServiceBusEmulatorHost.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Amqp;
using Amqp.Framing;
using Amqp.Listener;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -87,6 +88,12 @@ private ContainerHost BuildSecureServiceBusHost()
int port = Settings.Port;
Address address = new($"amqps://localhost:{port}");
ContainerHost host = new(new[] { address }, Settings.ServerCertificate);
host.AddressResolver += (c, attach) =>
{
// required for node.js SDK $cbs authentication
((Target)attach.Target).Address ??= attach.LinkName;
return null;
};

host.Listeners[0].HandlerFactory = _ => AzureHandler.Instance;
host.Listeners[0].SASL.EnableAzureSaslMechanism();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public static IFixture CustomizeAmqpMessage(this IFixture fixture, RestrictedDes
delivery.State = deliveryState ?? new Accepted();
delivery.Tag = fixture.CreateMany<byte>(16).ToArray();
deliverySetter.PropertyType.GetField("Buffer").SetValue(delivery, new ByteBuffer(1, true));
deliverySetter.SetValue(x, delivery);
})
);
Expand Down
4 changes: 3 additions & 1 deletion test/ServiceBusEmulator.RabbitMq.Tests/RabbitMqMapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public void ThatMappingIsSimetrical()
() => Assert.Equal(expectedMessage.ApplicationProperties.FromDescribedMap(), amqpMessage.ApplicationProperties.FromDescribedMap()),
//() => Assert.Equal(expectedMessage.DeliveryAnnotations.FromDescribedMap(), amqpMessage.DeliveryAnnotations.FromDescribedMap()),
//() => Assert.Equal(expectedMessage.Footer.FromDescribedMap(), amqpMessage.Footer.FromDescribedMap()),
() => Assert.Equal(expectedMessage.MessageAnnotations.FromDescribedMap(), amqpMessage.MessageAnnotations.FromDescribedMap())
() => Assert.Equal(expectedMessage.MessageAnnotations.FromDescribedMap(), amqpMessage.MessageAnnotations.FromDescribedMap()),

() => Assert.Equal((DateTime)amqpMessage.MessageAnnotations[new Symbol("x-opt-locked-until")], DateTime.UtcNow, TimeSpan.FromDays(2))
);
}

Expand Down

0 comments on commit 5d7f338

Please sign in to comment.