Spring Cloud Contract and plain Spring AMQP - spring

We are using plain Spring AMQP in our spring boot projects.
We want to make sure that our message consumers can test against real messages and avoid to test against static test messages.
Thus our producers could generate message snippets in a test phase that can be picked up by the consumer test to make sure it tests against the latest message version and see if changes in the producer break the consumer.
It seems like Spring Cloud Contract does exactly that. So is there a way to integrate spring cloud contract with spring amqp? Any hints in which direction to go would be highly appreciated.

Actually we don't support it out of the box but you can set it up yourself. In the autogenerated tests we're using an interface to receive and send messages so
you could implement your own class that uses spring-amqp. The same goes for the consumer side (the stub runner). What you would need to do is to implement and register a bean of
org.springframework.cloud.contract.verifier.messaging.MessageVerifier type for both producer and consumer. This should work cause what we're doing in the autogenerated tests is that we #Inject MessageVerifier
so if you register your own bean it will work.
UPDATE:
As #Mathias has mentioned it, the AMQP support is already there in Spring Cloud Contract https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_stub_runner_spring_amqp

Related

difference between usage of #RabbitListener() and usage of DirectMessageListenerContainer in consuming from a rabbitMQ in springboot

I am trying to configure concurrent consumers in spring to consume messages from RabbitMQ, in order to achieve that i have configured consumers in two ways
1.annotated a method with #RabbitListener(queues = "name of queue")
2.implementing "MessageListener" interface and overriding onMessage(Message message)
In my case both the ways worked fine, but i am unable to figure out what is the advantage/disadvantage of using #RabbitListener() for starting a consumer over the other way.
Also adding to that i have configured "DirectMessageListenerContainer" in my configuration and mapped it to "MessageListener" implementation to achieve concurrent consumers, my question here is can we do the same mapping for consumer implemented through #RabbitListener() and if so how. I couldnt find any source on how a consumer started with a #RabbitListener() annotated method can be configured with a "DirectMessageListenerContainer"
Any Help is appreciated.
#RabbitListener is simply a higher-level abstraction. It uses the listener container underneath.
When using spring boot, use the ...listener.type application property to specify which type of container you want.
The default is simple.

Mocking SchemaRegistryClient in stream processor Consumer

I have a Reactor-based Spring Boot Kafka stream processing app that I am working on writing integration tests for. I am using Spring's #EmbeddedKafka broker. It works great, I have it overriding the bootstrap broker urls that get configured on my reactive processor's consumer & publisher, but what I haven't figured out yet is how to deal with the schema registry for my processor when testing. I'm using Confluent's KafkaAvroSerializer and KafkaAvroDeserializer classes and just have the schema.registry.url field configured in my Spring app configs to get injected into the Kafka properties. I'm using Confluent's MockSchemaRegistryClient for the test producer and consumer, but what I need is a way to inject this mock client into the actual consumer and producer in my stream processor code, but I see no way to do that. Almost seems like I need something more like an embedded version of the schema registry to point them to like the embedded broker. Our build pipeline does not support spinning up containers otherwise I'd use Docker or Testcontainers. Anyone else solve this already? Any help or suggestions appreciated.
I managed to figure this out. If you use a url that begins with mock:// for your test's SerDes, and you override the schema.registry.url property in the #SpringBootTest annotation with the same mock url, then your processor's consumer and producer will also pick up and use this mock schema registry client, and everything just works!

JMS configuration for Spring Integration

I am trying to implement activemq(just want to receive messages) with spring integration.I cant find any clues how to provide java configuration for activemq. What are the minimum required components for job. Somewhere we have channel, adapter somewhere we dont. I am unable to understand spring concepts of adapter, channel and service activator. They are all feeling same to me. I find the integration documentation going above my head. I never had problems with understanding other spring modules(boot, mvc, cloud, batch). Can someone point me in the right direction or what is it that I am doing wrong.
You probably are missing the fact that Spring Integration is a reference implementation for well-known Enterprise Integration Patterns. So, please, consider to start from the theory and ideas. Then you can come back to Spring Integration as an API for those EIP. See respective book on the matter: https://www.enterpriseintegrationpatterns.com.
To read messages from JMS destination you need to use a JmsMessageDrivenEndpoint with respective ConnectionFactory injected.
There is nothing more about that than an ActiveMQConnectionFactory as a bean.
For example in tests we do like this:
new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false")
And an in-memory broker is started.
See a test class with Java DSL for some way how to configure JMS components: https://github.com/spring-projects/spring-integration/blob/master/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java

Spring sleuth kafkaTemplate injections

Have a project with spring boot 2.1.9, spring kafka and spring sleuth (2.1.6).
All's been going well till I reached the point of tracing messages to/from kafka.
Kafka messaging is done through:
kafkaTemplate.send(uri, pojo)
And here I realized that there is no injection into kafka messaging - both debugged points of doSend of Kafka, and printed the message, received from #KafkaListener (with looking for keys from brave...KafkaKeys), and never saw a note of tracing.
As I understand from the doc, these messaging are enabled by default (not that I havent enabling "messaging" or "integration").
Tried registering custom bean implementations of "Propagation.Setter" just to see if it's actually being called, and never seen this actually ping.
Additional note: I found that org.apache.kafka(from spring-kafka 2.2.9) ...KafkaProducer is used instead of Sleuth one's.
What am I missing?

Using rabbitmq to send String/Custom Object from one spring boot application to another

My requirement is to for starters send a string from one spring-boot application to another using AMQP.
I am new to it and I have gone through this spring-boot guide, so i know the basic fundamentals of Queue, Exchange, Binding, Container and listener.
So, above guide shows the steps when amqp is received in same application.
I am a little confused on where to start if I want to achieve above type of communication between 2 different spring-boot applications.
What are the properties needed for that, etc.
Let me know if any details required.
Just divide the application into two:
One without Receiver and ...
Another without Sender
Make sure your application and configuration etc stays the same. With Spring boot's built-in RabbitMQ, you will be able to run it alright.
Next step is to call sender as and when needed from your business logic.

Resources