Skip to content

Commit 54f4551

Browse files
authored
docs(ActiveMq): Add example (#1415)
1 parent 594ae5d commit 54f4551

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

docs/modules/activemq.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Apache ActiveMQ Artemis
2+
3+
[Apache ActiveMQ Artemis](https://activemq.apache.org/components/artemis/) is an open source project to build a multi-protocol, embeddable, very high performance, clustered, asynchronous messaging system.
4+
5+
Add the following dependency to your project file:
6+
7+
```shell title="NuGet"
8+
dotnet add package Testcontainers.ActiveMq
9+
```
10+
11+
You can start an Apache ActiveMQ Artemis container instance from any .NET application. This example uses xUnit.net's `IAsyncLifetime` interface to manage the lifecycle of the container. The container is started in the `InitializeAsync` method before the test method runs, ensuring that the environment is ready for testing. After the test completes, the container is removed in the `DisposeAsync` method.
12+
13+
=== "Base test class"
14+
```csharp
15+
--8<-- "tests/Testcontainers.ActiveMq.Tests/ArtemisContainerTest.cs:UseArtemisContainer"
16+
}
17+
```
18+
=== "Without auth"
19+
```csharp
20+
--8<-- "tests/Testcontainers.ActiveMq.Tests/ArtemisContainerTest.cs:UseArtemisContainerNoAuth"
21+
```
22+
=== "Default credentials"
23+
```csharp
24+
--8<-- "tests/Testcontainers.ActiveMq.Tests/ArtemisContainerTest.cs:UseArtemisContainerDefaultAuth"
25+
```
26+
=== "Custom credentials"
27+
```csharp
28+
--8<-- "tests/Testcontainers.ActiveMq.Tests/ArtemisContainerTest.cs:UseArtemisContainerCustomAuth"
29+
```
30+
31+
Connect to the container and produce a message:
32+
33+
=== "EstablishesConnection"
34+
```csharp
35+
--8<-- "tests/Testcontainers.ActiveMq.Tests/ArtemisContainerTest.cs:ArtemisContainerEstablishesConnection"
36+
```
37+
38+
The test example uses the following NuGet dependencies:
39+
40+
=== "Package References"
41+
```xml
42+
--8<-- "tests/Testcontainers.ActiveMq.Tests/Testcontainers.ActiveMq.Tests.csproj:PackageReferences"
43+
```
44+
45+
To execute the tests, use the command `dotnet test` from a terminal.
46+
47+
--8<-- "docs/modules/_call_out_test_projects.txt"

mkdocs.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ nav:
4848
- examples/aspnet.md
4949
- Modules:
5050
- modules/index.md
51-
- modules/cassandra.md
52-
- modules/pulsar.md
53-
- modules/eventhubs.md
54-
- modules/servicebus.md
51+
- modules/activemq.md # Apache
52+
- modules/cassandra.md # Apache
53+
- modules/pulsar.md # Apache
54+
- modules/eventhubs.md # Azure
55+
- modules/servicebus.md # Azure
5556
- modules/db2.md
5657
- modules/elasticsearch.md
5758
- modules/mongodb.md

tests/Testcontainers.ActiveMq.Tests/ArtemisContainerTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Testcontainers.ActiveMq;
22

3+
// # --8<-- [start:UseArtemisContainer]
34
public abstract class ArtemisContainerTest : IAsyncLifetime
45
{
56
private readonly ArtemisContainer _artemisContainer;
@@ -24,7 +25,9 @@ public Task DisposeAsync()
2425
{
2526
return _artemisContainer.DisposeAsync().AsTask();
2627
}
28+
// # --8<-- [end:UseArtemisContainer]
2729

30+
// # --8<-- [start:ArtemisContainerEstablishesConnection]
2831
[Fact]
2932
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
3033
public async Task EstablishesConnection()
@@ -67,7 +70,9 @@ await producer.SendAsync(producedMessage)
6770

6871
Assert.Equal(producedMessage.Text, receivedMessage.Body<string>());
6972
}
73+
// # --8<-- [end:ArtemisContainerEstablishesConnection]
7074

75+
// # --8<-- [start:UseArtemisContainerDefaultAuth]
7176
[UsedImplicitly]
7277
public sealed class DefaultCredentialsConfiguration : ArtemisContainerTest
7378
{
@@ -76,7 +81,9 @@ public DefaultCredentialsConfiguration()
7681
{
7782
}
7883
}
84+
// # --8<-- [end:UseArtemisContainerDefaultAuth]
7985

86+
// # --8<-- [start:UseArtemisContainerCustomAuth]
8087
[UsedImplicitly]
8188
public sealed class CustomCredentialsConfiguration : ArtemisContainerTest
8289
{
@@ -89,7 +96,9 @@ public CustomCredentialsConfiguration()
8996
{
9097
}
9198
}
99+
// # --8<-- [end:UseArtemisContainerCustomAuth]
92100

101+
// # --8<-- [start:UseArtemisContainerNoAuth]
93102
[UsedImplicitly]
94103
public sealed class NoAuthCredentialsConfiguration : ArtemisContainerTest
95104
{
@@ -98,4 +107,5 @@ public NoAuthCredentialsConfiguration()
98107
{
99108
}
100109
}
110+
// # --8<-- [end:UseArtemisContainerNoAuth]
101111
}

tests/Testcontainers.ActiveMq.Tests/Testcontainers.ActiveMq.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
<IsPublishable>false</IsPublishable>
66
</PropertyGroup>
77
<ItemGroup>
8+
<!-- -8<- [start:PackageReferences] -->
89
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
910
<PackageReference Include="coverlet.collector"/>
1011
<PackageReference Include="xunit.runner.visualstudio"/>
1112
<PackageReference Include="xunit"/>
1213
<PackageReference Include="Apache.NMS.ActiveMQ"/>
14+
<!-- -8<- [end:PackageReferences] -->
1315
</ItemGroup>
1416
<ItemGroup>
1517
<ProjectReference Include="../../src/Testcontainers.ActiveMq/Testcontainers.ActiveMq.csproj"/>

0 commit comments

Comments
 (0)