Skip to content

Commit 90f04b4

Browse files
committed
Read envs file
1 parent 21a7601 commit 90f04b4

File tree

5 files changed

+23
-33
lines changed

5 files changed

+23
-33
lines changed

README.md

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,35 @@ To run the code sample you have 3 options in terms of transports:
1010
The RabbitMQ Broker is started as part of the docker compose process
1111
>
1212
13-
Run docker command bellow from the `src` folder in a CLI
13+
Run docker command below from the `src` folder in a CLI
1414
```cmd
1515
docker compose -f docker-compose-base.yml -f compose-rabbitmq.yml --env-file rabbit.env up -d
1616
```
1717
## **Azure ServiceBus**
1818

19-
Configure the access to your Azure Service Bus namespace by editing the variables in `asb.env`
19+
Configure the access to your Azure Service Bus namespace by editing the variables in `src/asb.env`
2020

21-
```cmd
21+
```env
2222
CONNECTIONSTRING="Endpoint=sb://[NAMESPACE].servicebus.windows.net/;SharedAccessKeyName=[KEYNAME];SharedAccessKey=[KEY]"
2323
```
2424

25-
Set the same environment variables on your machine:
26-
27-
```cmd
28-
setx CONNECTIONSTRING_AZURESERVICEBUS "Endpoint=sb://[NAMESPACE].servicebus.windows.net/;SharedAccessKeyName=[KEYNAME];SharedAccessKey=[KEY]"
29-
```
30-
31-
Run docker command bellow from the `src` folder in a CLI
25+
Run docker command below from the `src` folder in a CLI
3226

3327
```cmd
3428
docker compose -f docker-compose-base.yml -f compose-azure.yml --env-file asb.env up -d
3529
```
3630

3731
## **Amazon SQS**
3832

39-
Configure the access to your SQS namespace by editing the variables in `sqs.env`
33+
Configure the access to your SQS namespace by editing the variables in `src/sqs.env`
4034

41-
```cmd
35+
```env
4236
AWS_REGION="<region>"
4337
AWS_ACCESS_KEY_ID="<access-key>"
4438
AWS_SECRET_ACCESS_KEY="<secret-access-key>"
4539
```
4640

47-
Set the same environment variables on your machine:
48-
49-
```cmd
50-
setx AWS_REGION "<region>"
51-
setx AWS_ACCESS_KEY_ID "<access-key>"
52-
setx AWS_SECRET_ACCESS_KEY "<secret-access-key>"
53-
```
54-
55-
Run docker command bellow from the `src` folder in a CLI
41+
Run docker command below from the `src` folder in a CLI
5642

5743
```cmd
5844
docker compose -f docker-compose-base.yml -f compose-sqs.yml --env-file sqs.env up -d

src/Helper/BusRegistrationConfiguratorExt.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MassTransit;
1+
using dotenv.net;
2+
using MassTransit;
23

34
public static class BusRegistrationConfiguratorExt
45
{
@@ -10,10 +11,11 @@ public static void SetupTransport(this IBusRegistrationConfigurator x, string[]
1011
{
1112
x.UsingAmazonSqs((ctx, cfg) =>
1213
{
13-
cfg.Host(Environment.GetEnvironmentVariable("AWS_REGION"), h =>
14+
var envs = DotEnv.Read(new DotEnvOptions(envFilePaths: [Path.GetFullPath("../../../sqs.env")]));
15+
cfg.Host(envs["AWS_REGION"], h =>
1416
{
15-
h.AccessKey(Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID"));
16-
h.SecretKey(Environment.GetEnvironmentVariable("AWS_SECRET_ACCESS_KEY"));
17+
h.AccessKey(envs["AWS_ACCESS_KEY_ID"]);
18+
h.SecretKey(envs["AWS_SECRET_ACCESS_KEY"]);
1719
});
1820

1921
cfg.ConfigureEndpoints(ctx);
@@ -22,10 +24,10 @@ public static void SetupTransport(this IBusRegistrationConfigurator x, string[]
2224
}
2325
else if (args.Contains("--azureservicebus"))
2426
{
25-
27+
var envs = DotEnv.Read(new DotEnvOptions(envFilePaths: [Path.GetFullPath("../../../asb.env")], ignoreExceptions: false));
2628
x.UsingAzureServiceBus((context, cfg) =>
2729
{
28-
cfg.Host(Environment.GetEnvironmentVariable("CONNECTIONSTRING_AZURESERVICEBUS"));
30+
cfg.Host(envs["CONNECTIONSTRING"]);
2931

3032
cfg.ConfigureEndpoints(context);
3133
});
@@ -64,8 +66,9 @@ public static void SetupTransport(this IBusRegistrationConfigurator x, string[]
6466

6567
if (cfg is IServiceBusReceiveEndpointConfigurator sb)
6668
{
67-
sb.ConfigureDeadLetterQueueDeadLetterTransport();
68-
sb.ConfigureDeadLetterQueueErrorTransport();
69+
// Uncomment this code to use deadletter
70+
//sb.ConfigureDeadLetterQueueDeadLetterTransport();
71+
//sb.ConfigureDeadLetterQueueErrorTransport();
6972
}
7073
});
7174
}

src/Helper/Helper.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="dotenv.net" Version="3.2.1" />
910
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.3.0" />
1011
<PackageReference Include="MassTransit.RabbitMQ" Version="8.3.0" />
1112
<PackageReference Include="MassTransit.AmazonSQS" Version="8.3.0" />

src/asb.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
TRANSPORTTYPE="NetStandardAzureServiceBus"
22
# Update this variable with the value from Azure portal
3-
CONNECTIONSTRING="Endpoint=sb://[NAMESPACE].servicebus.windows.net/;SharedAccessKeyName=[KEYNAME];SharedAccessKey=[KEY]"
3+
CONNECTIONSTRING="Endpoint=sb://masstr.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XzF01z+3BcP5qWJUq7ba0Nm00nM7T7wS3+ASbMUaZ1Q="

src/sqs.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TRANSPORTTYPE="AmazonSQS"
22

33
# Update these variable values
4-
AWS_REGION="<region>"
5-
AWS_ACCESS_KEY_ID="<access-key>"
6-
AWS_SECRET_ACCESS_KEY="<secret-access-key>"
4+
AWS_REGION="us-east-1"
5+
AWS_ACCESS_KEY_ID="AKIAJQHSOSAFGR4X6FPQ"
6+
AWS_SECRET_ACCESS_KEY="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"

0 commit comments

Comments
 (0)