How to do a pact contract verification test from a json contract - spring-webflux

I know to do pact verification using
#pactBroker(host="hostname", authentication="someAuthtextInbase64")
where all the contract details are present and I can connect and verify.
Now I want to run a pact test without involving the pact broker as my consumer is not ready, my consumer provided a valid contract json and I am suppose to verify it from provider end with just the contract json? Could any one help on this please?

See https://docs.pact.io/implementation_guides/jvm/provider/junit#pact-source. You probably want the #PactFolder or #PactUrl annotation.
Now I want to run a pact test without involving the pact broker as my consumer is not ready, my consumer provided a valid contract json and I am suppose to verify it from provider end with just the contract json?
Even if the consumer is not ready, they should still publish to the Pact Broker. This is what branches/tags etc. are for. You might like to see https://docs.pact.io/pact_nirvana or https://docs.pactflow.io/docs/workshops/ci-cd/ for more on the recommended workflow.

Related

Run ktor test using `testApplication` without a client call

Is it possible to write a ktor test without any client call? We have a ktor kafka consumer service that executes http calls. The shape of our test is:
startAndConfigureWiremock()
testApplication{
application{
changeConfiguration()
}
sendKafkaMessage()
verifyExternalCall()
}
but the tests with any client calls do not work. Test code verifyExternalCall() is executed before the service is up and blocks the startup without any testBlocking.
When we try to add parallelism like GlobalScope.launch it runs the application, but it just starts and stops.
Looks like testApplication needs a client call to work at all and even ktor test relay on it: https://github.com/ktorio/ktor/blob/8b784f45a6339728ce7181498a5854b29bf9d2a5/ktor-server/ktor-server-core/jvmAndNix/test/io/ktor/server/application/HooksTest.kt#L81
This might not be the answer you are looking for but...
This definately looks like the incorrect place and method for performing this test.
Ktor is for building web APIs, it is for dealing with things like routing and serialisation. Why are you testing if an internal service is being started and is polling kafka for messages? This has nothing to do with ktor.
If you really want to do an integration test on this service rather:
do not start ktor
start kafka
start your Kafka polling service
send your message
do your verification
If you really want to check that your kafka service is started by your ktor application just do a verification that some "startKafkaConsumer" function was called in your start up. This should most likely be done on some injected mock of your consuming service.

Which option is more suitable for microservice? GRPC or Message Brokers like RabbitMQ

I want develop a project in microservice structure.
I have to use php/laravel and nodejs/nestjs
What is the best connection method between my microservices. I read about RabbitMQ and NATS messaging
and also GRPC
Which option is more suitable for microservice?
and why?
Thanks in advance
The technologies address different needs.
gRPC is a mechanism by which a client invokes methods on remote (although they needn't be) server. The client is tightly-coupled (often through load-balancers) with servers that implement the methods.
E.g. I (client) call Starbucks (service) and order (method) a coffee.
gRPC is an alternative to REST, GraphQL, and other mechanisms used to connect clients with servers though some form of API.
Message brokers (e g NATS, Rabbit) provide a higher-level abstraction in which a client sends messages to an intermediate service called a broker (this could be done using gRPC) and the broker may queue messages and either ship them directly to services (push) or wait for a service to check its subscription (pull).
E.g. I (client) post a classified ad on some site (broker). Multiple people may see my ad (subscriber) and offer to buy (method) the items from me. Some software robot may subscribe too and contact me offering to transport or insure the things I'm selling. Someone else may be monitoring sales of widgets on the site in order to determine whether there's a market for opening a store to sell these widgets etc.
With the broker, the client may never know which servers implement the functionality (and vice versa). This is a loosely-coupled mechanism in which services may be added and removed independently of the client.
If you need a synchronous response on 1:1 service call use gRPC
If you don't care which service will consume messages (asynchronous & no tight coupling between services) use RabbitMQ
If you need distributed system to keep events history and reuse later on another service use Kafka
Basically, it comes down to whether you want an Async communication between services or not.
That is when you can decide between real-time communication services (Sync) such as gRPC or RPC & Message Queueing ones (Async) such as RabbitMQ, Kafka or Amazon SQS.
Here are also some good answers by other users:
https://dev.to/hypedvibe_7/what-is-the-purpose-of-using-grpc-and-rabbitmq-in-microservices-c4i#comment-1d43
https://stackoverflow.com/a/63420930/9403963

When to NOT use a message broker such as RabbitMQ in a micro-services architecture?

I am new to the concept of messaging brokers such as RabbitMQ and wanted to learn some best practices.
RabbitMQ seems to be a great way to facilitate asynchronous communication between micro-services, however, I have a beginners question that I could not find an answer to anywhere else.
When would one NOT use a message broker such as RabbitMQ in a micro-services architecture?
As an example:
Let's say I have two services. Service A and Service B (auth service)
The client makes a request to service A which in turn must communicate with service B (auth service) to authenticate the user and authorize the request. (using Basic Auth)
Internet
Client ----------------> Service A +-------> Service B [Authenticate/Authorization]
HTTP request HTTP or AMQP??
In my limited understanding, the issue I can foresee with using an AMQP in scenarios such as the one outlined above is service A being able to process the request and send a response to the client within an acceptable timeframe, given it must wait for service B to consume and respond to a message.
Essentially, is it a bad idea to make Service A wait for a response from Service B via an AMQP?
Or have I missed the point of an AMQP entirely??
Well actually what you are describing is mostly close to the HTTP.
HTTP is synchronous which means that you have to wait for a response. The solution to this issue is AMQP as you mention. With AMQP you don't necessarily need to wait(you can configure it).
Its not necessarily a bad idea but what most microservices depend on is something called eventual consistency. As this will be a quite long answer with a lot of ifs I would suggest taking a look into Microservices Architecture
For example here is the part about the http vs amqp since its mostly a question about sychronous vs asychronous communication
It goes into great detail about different approaches of microservices design listing pros and cons for your specific question and others.
For example in your case the Auth would happen at the API gateway as its not considered best practice to leave the microservices open for all the client applications.

Consuming a WCF service without having any service contract or data contract reference during compilation

I have been googling for quite some time now but cannot find a definite answer.
I want to consume a wcf service, whose address will be provided at runtime.
The user will enter the address of the wcf service at runtime.
During compilation I have no idea of the service contract or the data contract or the endpoints of the wcf service.
Could someone please let me know how to achieve this requirement ?
This was the original idea behind UDDI. Before making a call, the client would query some central repository and obtain the address, contracts, and bindings of the service endpoint. It would then use this information to assemble and call the channel.
Some ESBs work on this principal - the call to UDDI can also be logged centrally, so an audit is kept of all service calls made within the enterprise.
Microsoft implemented it's own UDDI server which can be integration into SCOM for this purpose.

Is NServiceBus suitable for general as well specific client notifications

I am looking at various options for a WCF based publish subscribe framework. Say I have one WCF web service that will be the publisher and 1000 clients registered as subscriber. For some published messages all clients will be interested but at the same time I wish the ability to notify a single client with a specific message. On receiving notification the client will call other web service methods on the web service.
Is NServiceBus suitable for this kind of scenario ?
If I use MSMQ for transport does it mean that every PC where the client is installed requires a queue to be created ?
Some of the challenges include how you want the publisher to behave when a given subscribing client is down - do you want that message to be available when the subscriber comes back up? If so, then some kind of durable messaging is needed between them - like MSMQ.
Your question about notifying a single client, is that as a result of a request sent by that client? If so, then standard NServiceBus calls in the form of Bus.Reply will do it for you. When using WCF, if the response is to be asynchronous you'll need to use callback contracts.
NServiceBus can do all the things you described, and has the ability to automatically install MSMQ and create queues so that greatly simplifies client-side deployments.
You also have the ability with NServiceBus to expose messages over WCF so you can support non-NServiceBus clients if you need to as well. It also has its own http gateway and XSD schemas which can allow clients on non-Windows platforms to interoperate even without using WCF.
Hope that answers your questions.