How to enable query logging with Spring Data Redis? - spring

For Spring Data JDBC I can use logging.level.org.springframework.jdbc.core=TRACE in order to see what queries are being executed.
What is analogous option for Spring Data Redis?

According to https://github.com/spring-projects/spring-data-redis/issues/1586 and https://github.com/spring-projects/spring-data-redis/issues/1321 there is no way of logging queries besides using MONITOR command inside redis-cli.

Related

Can we use hibernate with spring web flux

I am new to reactive programming I have started using webflux, previously I work on spring boot there I have used hibernate as a ORM framework. My doubt is what is replace of hibernate in reactive stack , which framework I have to use to connect & implement database logic.
I am using mongoDB.
Thanks in advance.
you have to use either R2DBC or Hibernate reactive.
if you migrating an old service from spring boot to webflux, I recommended you to use Hibernate reactive.
when you use R2DBC, you can't use hibernate mappings and annotations.
according to hibernate reactive documentation:
When using a stateless session, you should be aware of the following additional limitations:
persistence operations never cascade to associated instances,
changes to #ManyToMany associations and #ElementCollections cannot be
made persistent, and
operations performed via a stateless session bypass callbacks.
Hibernate is based on JDBC. JDBC is blocking. Blocking APIs don't work well in reactive stacks. Also, Hibernate under the hood uses ThreadLocals which makes it even worse candidate for reactive applications.
For Webflux, as the alternative to Hibernate you should look into Spring Data R2DBC which does the basic database result to Java object mapping, but keep in mind that it's not a full fledge ORM like Hibernate.
You may also want to give it a try to Hibernate Reactive. With this you can use the power of Hibernate mappings in a reactive non blocking way. One thing that will not work though (at least not yet) is declarative transaction management with #Transactional.
It depends on what database driver you are using.
If using the jdbc driver to talk to your database, then yes you can use hibernate. But important to note is that the JDBC spec is blocking so every call to the database will be blocking, and must be placed on its own scheduler (thread) and you will most likely not get the full performance benefits of a fully reactive application.
If you want a fully reactive application you must use a database driver that supports the R2DBC protocol. Hibernate does not support R2DBC so can not be used if you want a fully reactive application.
Hibernate is most commonly used with relation database such as mysql, postgres, oracle etc and not NoSql databases such as monogDB.
If you are using MongoDB then there is full support for R2DBC and there is no need for hibernate.

Can we use Couchbase as the message store for Spring Integration

We are implementing Spring Integration aggregator and using JDBC message data store. In our environment we have Couchbase and Oracle DB. I don't want to use Oracle DB, can we use couchbase as the message store.
If yes, can you please suggest the approach.
There is a MessageStore strategy that you would need to implement and then configure as any other message store in your Spring Integration components that required it. Here is a bit more info.

How can Spring JPA use two different database connections for read and write operations?

we use in our backend AWS Aurora which has two instances, one for read+write-access and one only for read access.
In our backend we use Spring data JPA to manage our Entities in the database. Would it now be possible, that spring will use the read node for selecting data and the read/write node only for write operations?
How could we configure that? Therefore the read instance has another hostname this instance do nothing.
Thx.

How to use Apache Ignite as a layer between Spring Boot app and MongoDB?

I have a Spring Boot application that uses MongoDB. My plan is to store data in a distributed caching system before it gets inserted into Mongo. If the database fails, the caching will have a queue and send to the DB once it is up. So, the plan is to make the caching layer in between the application and Mongo.
Can you suggest some ideas on how to implement this using Apache Ignite?
Take a look at write-behind cache store mode. It retries writing to the underlying database if insertion to the underlying DB fails. Let me know how it works for you.
You can also implement a custom CacheStore for an Ignite cache that will do the caching and enable write through for it. If the connection is lost, then you'll be able to collect entries in a buffer, while retrying to establish the connection back.
See more: https://apacheignite.readme.io/docs/3rd-party-store

how to use redismetricrepository in spring boot

I am working on spring boot actuator and able to see the metrics of my application. But I want to store these metrics to some db. In Spring doc it has been mentioned that RedisMetricRepository provides option for storing metrics to redis db. But I dont how to make use of this RedisMetricRepository to store metrics to redis db.Kindly help me out how to use RedisMetricRepository for storing metrics to redis db.
You can just create a #Bean of type RedisMetricRepository. I suspect that will just store the metrics in Redis immediately. I prefer to buffer in memory and export to Redis periodically. Here's a sample using #Scheduled to export to Redis every 5s): https://github.com/scratches/aggregator/blob/master/generator/src/main/java/demo/GeneratorApplication.java#L61.

Resources