I am having issues testing MassTransit with LocalStack, but with the real SNS/SQS in AWS everything works fine, so I suspect it's an issue with LocalStack unless MassTransit requires something else than configuring ServiceURL. See https://github.com/MassTransit/MassTransit/issues/1476
I run LocalStack as following, just with SNS and SQS
docker run -it -e SERVICES=sns,sqs -e TEST_AWS_ACCOUNT_ID="000000000000" -e DEFAULT_REGION="us-east-1" -e LOCALSTACK_HOSTNAME="localhost" -e -rm --privileged --name localstack_main -p 4566:4566 -p 4571:4571 -p 8080-8081:8080-8081 -v "/tmp/localstack:/tmp/localstack" -v "/var/run/docker.sock:/var/run/docker.sock" -e DOCKER_HOST="unix:///var/run/docker.sock" -e HOST_TMP_FOLDER="/tmp/localstack" "localstack/localstack"
Now with MassTransit I create the bus and start it. The only change I make for MassTransit to work with LocalStack is setting the ServiceURL
in SNS and SQS. The rest should work in the same way (I think)
var region = "localhost:4566";
var accessKey = "test";
var secretKey = "test";
var busControl = Bus.Factory.CreateUsingAmazonSqs(c =>
{
var hostAddress = new Uri($"amazonsqs://{region}")
var hostConfigurator = new AmazonSqsHostConfigurator(hostAddress);
hostConfigurator.AccessKey(accessKey);
hostConfigurator.SecretKey(secretKey);
hostConfigurator.Config(new AmazonSimpleNotificationServiceConfig {ServiceURL = $"http://{region}"});
hostConfigurator.Config(new AmazonSQSConfig {ServiceURL = $"http://{region}"});
c.Host(hostConfigurator.Settings);
});
When running my project I can connect and publish events, no errors. I subscribe to events, no errors. I can see the topics, subscriptions and queue are properly created in LocalStack.
I can also see with Commandeer that there are "invisible" messages in the queue (not sure what that is) so it seems the problem is in the receiving part.
Is there anything additional requirement to configure in MassTransit to consume published events?
UPDATE 1: One interesting thing is that I can keep the subscriber listening for long time and during this time Commandeer shows there are invisible messages in the queue. As soon as I stop the subscriber (and my application) I can see that Commandeer moves messages from "invisible" to "messages". Cannot peek messages though.
localstack/localstack latest 86200da6e9fa 10 months ago 880MB
– Chris Patterson