Integration tests with RabbitMq¶
To run integration tests with RabbitMq we need to follow below mentioned steps:
- Make sure RabbitMq instance is running in local, follow these steps https://dev.azure.com/MAJORITY/Documentation/_wiki/wikis/Main/330/RabbitMq-setup-in-local
- In integration test, AssemblyInitialize enable rabbitMq
builder.ConfigureTestMessageBus(c => { c.UseInMemoryMessageBus = false; c.UseRabbitMqMessageBus = true; }); - In all values.yaml files in the repo that already contain a config
global-servicebus-configadd this config:global-rabbitmq-config - Add above config(
global-rabbitmq-config.json) file with these values
{ "PoolMaximumRetained": "20", "MaxRetries": "3", "SendRetryMillisecondsDelay": "1000" } - Add these secrets in local_usersecrets
"global-rabbitmq-credential:UserName": "user", "global-rabbitmq-credential:Port": "5672", "global-rabbitmq-credential:Password": "password", "global-rabbitmq-credential:Host": "localhost", "global-rabbitmq-credential:VirtualHost": "/" - Add in app-settings.json
"messagebus-config": { "UseRabbitMqForPublish" : true, "UseRabbitMqForSession":true } - (run the init secrets script)
These changes will make run integration tests using rabbitMq in which basically messages are published using RabbitMq.
Sample PR: https://dev.azure.com/MAJORITY/Bank/_git/bank-braze/pullrequest/48965?_a=files
If need to register events in actual environment(stage/prod) with RabbitMq meaning not only for integration test then need to do below changes:
1. In Application Module where this is added 'builder.RegisterModule
2. In integration test, AssemblyInitialize then we don't need to set UseRabbitMqMessageBus as we will register rabbitmq module in application module. So, only this is needed to disable inMemory message bus.
builder.ConfigureTestMessageBus(c => { c.UseInMemoryMessageBus = false; });
3. Above 2 steps will help to register messages with both providers (asb and rabbitmq). But if we need to send event as well with RabbitMq, then in configuration repo -> app-settings-xxxx.json we should add this only to publish normal events, don't enable session in actual environment. Sample PR https://dev.azure.com/MAJORITY/Bank/_git/bank-configuration/pullrequest/49737?_a=files
"messagebus-config": {"UseRabbitMqForPublish": true }
Note: Session based and scheduling will still happen using service bus in actual environment. Also before this can be done make sure all areas are using new MessageAttribute around events to define EventName.
Note
if you need to run regression tests locally against stage, and the regression test needs access to rabbit (not the services but the test itself) you will need to have the below entry in your hosts file. (if not added Automatically)
10.200.80.236 minority-rabbitmq-persist.rabbitmq