Hello Everyone, I'm trying to implement Pact for ...
# general
r
Hello Everyone, I'm trying to implement Pact for my lambda and my use case is as follows: I have a lambda with an SQS setup so I have one Consumer which is my lambda and I have multiple Providers (Producers) who can put data into the SQS and then to my consumer (lambda). When I try to implement this scenario I can't find a way to have a setup with one Consumer and multiple providers. Is this scenario possible to implement in Pact?
m
I haven't done with SQS specifically (I'm using EventBridge), but it's working ok for me having multiple providers - just create a separate MessageConsumer for each Provider you're expecting a message from
👍 1
In my case, the type of message and structure is different for each provider so it makes sense to identify them separately anyway (vs these providers all create identical messages)
r
But having multiple consumers would be a bit strange. Because you actually have one consumer for all your providers. Of course, having multiple consumers would make it possible but I think it's having some drawbacks. Ex: In Pacflow you will not be able to see the big picture in the graphs because we are creating Provider-Consumer for each state we want to verify.
m
I think Mike is talking about the test class - you need to create a pact for each provider. Logically you can have one consumer and multiple providers
What language are you using?
m
Yep, apologies for that not being very clear. In my example, I have a consumer "ig-watcher" which listens for events from multiple providers [e.g. here "ig-analysis" and "ig-tracker"], so there's then a test file for each, where each declares the pact between consumer and provider, e.g. test_pact_analysis_consumer.py
Copy code
CONSUMER_NAME = "ig-watcher"
PROVIDER_NAME = "ig-analysis"


@pytest.fixture(scope="session")
def pact(consumer_version):
    pact = MessageConsumer(CONSUMER_NAME, tag_with_git_branch=True, version=consumer_version).has_pact_with(
        Provider(PROVIDER_NAME),
        pact_dir=PACT_DIR,
        publish_to_broker=True,
        broker_base_url=PACT_BROKER_URL,
        broker_username=PACT_BROKER_USERNAME,
        broker_password=PACT_BROKER_PASSWORD,
    )
    yield pact

...followed by pact tests using pact, between provider ig-analysis -> consumer ig-watcher
then the same but for the other providers involved test_pact_tracker_consumer.py
Copy code
CONSUMER_NAME = "ig-watcher"
PROVIDER_NAME = "ig-tracker"


@pytest.fixture(scope="session")
def pact(consumer_version):
    pact = MessageConsumer(CONSUMER_NAME, tag_with_git_branch=True, version=consumer_version).has_pact_with(
        Provider(PROVIDER_NAME),
        pact_dir=PACT_DIR,
        publish_to_broker=True,
        broker_base_url=PACT_BROKER_URL,
        broker_username=PACT_BROKER_USERNAME,
        broker_password=PACT_BROKER_PASSWORD,
    )
    yield pact

...followed by pact tests using pact, between provider ig-tracker -> consumer ig-watcher
When the "pact" object [can't think of the correct terminology right now] finishes/finalises/closes etc it will submit the appropriate pact for that pair. ...then another "pact" will do the same for the other pairs. My graph in the broker does look quite horrible since multiple consumers can receive and consume the same message [bridge vs queue] but that's another problem 😅
☝️ 1
r
Hi Matt, Hi Mike Thank you for your response. @Matt (pactflow.io / pact-js / pact-go) I'm using JS in the consumer and Kotlin in the provider. @Mike Geeves Thank you mike for your examples. Now I understand it better. Thank you guys
👍 2