Hey everyone, we have multiple consumers consumin...
# pact-jvm
s
Hey everyone, we have multiple consumers consuming the same message from provider. The provider verification test classes for all these consumers look absolutely same. the only difference is the @Consumer("consumerName") annotation. It is creating a lot of duplicate code. Is there a way i could declare multiple consumer annotations, or multiple consumers names in the same annotation or reuse the providerverification methods. I tried to re-use the methods by putting them all in a AbstractFile and extending my consumers from it. In this case I start getting the below error:
Unable to fetch provider method ...
m
What happens if you remove the
@Consumer
annotation on the method - can you still select the correct consumers from the
@PactBroker
annotation?
s
i have put the @Consumer annotation on the class , not on the method. let me share some code snippet below the child class for specific consumer
Copy code
@Consumer("consumerName")
@Provider("providerName")
public class VcOrderEventsMessagePV extends AbstractOrderChangeNotificationPV {
the parent class containing providerverification methods for all consumers
Copy code
public class AbstractOrderChangeNotificationPV extends AbstractContractVerifierTest {  @BeforeEach
    public void beforeEach(PactVerificationContext context) {
        LOG.debug("beforeEach({})", context);
        setMessageTestTarget(context);
    }

    @TestTemplate
    @ExtendWith(PactVerificationSpringProvider.class)
    public void testOrderChangeNotification(Pact pact, Interaction interaction, PactVerificationContext context) {
        if (context == null) {
            return;
        }
        context.verifyInteraction();
    }

    @PactVerifyProvider(ProviderVerificationNames.RESTAURANT_CP_RECEIVED)
    public String restaurantPickupOrderReceived() {
        return getRestaurantCustomerPickupMessage(RECEIVED);
    }
grandparent class containing the methods needed for setting up the system in the correct state
Copy code
@PactBroker
@IgnoreNoPactsToVerify
@AllowOverridePactUrl
public abstract class AbstractContractVerifierTest extends AbstractOrderEventDrivenTest {
consumer is deprecated in pactbroker
m
Iโ€™m guessing itโ€™s deprecated in favour of consumer version selectors
s
yes
u
Remove the
@Consumer
annotation as Matt said
s
yeah after making the changes it is working correctly. so to summarize, if we need to add multiple consumers we can use consumerversionselector in pactbroker annotation. Thanks a lot ๐Ÿ˜„ ๐Ÿป
๐Ÿ‘ 1