Configuring Spring Data Redis with Lettuce for Redis master/slave - java

Using Lettuce, how do we configure Spring Data Redis running on host x at port 6379 and slave running on the same or different host but at port 6380?

That's a feature which will be included in the upcoming Spring Data Redis 2.1 release.
You would configure LettuceConnectionFactory similar to:
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
.readFrom(ReadFrom.REPLICA)
.build();
LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration("x", 6379),
configuration);
Lettuce auto-discovers masters and replicas from a static (not managed with Redis Sentinel) setup.

Related

Accept Proxy Protocol V2 Traffic with Jetty in Spring Boot

I am trying to configure Jetty 9.4.39.v20210325 in java Spring Boot 2.4.5 to accept proxy protocol V2 traffic. I want to do this programmatically in a spring configuration class. This is the method I wrote in the SharedConfiguration.java configuration class based on the Proxy Protocol section on the bottom of this page.
#Bean
public ConfigurableServletWebServerFactory
jettyCustomizer() {
JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
factory.addServerCustomizers(server -> {
ProxyConnectionFactory proxyConnectionFactory = new ProxyConnectionFactory();
ServerConnector serverConnector = new ServerConnector(server, proxyConnectionFactory);
server.addConnector(serverConnector);
});
return factory;
}
The HTTP traffic is coming from an AWS EC2 network load balancer (NLB) and the balancer has proxy protocol V2 traffic enabled.
I am getting this response when I activate an endpoint in my service with the proxy protocol traffic:
Bad Message 400
reason: Illegal character CNTL=0x0
Does anyone know how I can get my service to accept this proxy protocol V2 traffic? I'm unsure if I am configuring Jetty correctly to do so.
Thanks!
I have since figured out the problem with my configuration, I was adding a new server connector instead of changing the one already in the Jetty server.
Here is the correct approach:
#Bean
public ConfigurableServletWebServerFactory jettyCustomizer() {
JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
factory.addServerCustomizers(server -> {
ServerConnector serverConnector = (ServerConnector) server.getConnectors()[0];
serverConnector.addFirstConnectionFactory(new ProxyConnectionFactory());
});
return factory;
}
Here I am getting the active server connector and mutating it to also contain a ProxyConnectionFactory which allows Jetty to accept the proxy protocol traffic.

Setup client side SASL authentication to connect with two different kafka clusters

I have spring boot application which connect to my kafka cluster.
Application(as kafka client) uses SASL authentication and I specified JAAS configuration through System.setProperty() before initializing kafka producer and consumer.
It is working fine with single kafka cluster setup.
kafka_client_jaas.conf
KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="myClusterUser"
password="user-secret";
};
MyKafkaProducer.java
…
private void init()
{
System.setProperty("java.security.auth.login.config", "kafka_client_jaas.conf");
…
}
Now I have a third party(someone else’s) kafka cluster which is completely disconnected from my kafka cluster. Third party kafka cluster also uses SASL authentication.
How java application can connect to two different kafka clusters and both clusters required SASL authentication?
Username and password are different for both the clusters and I can set only one JAAS config file in java.security.auth.login.config.
Since Kafka 0.10.2, you can use the sasl.jaas.config setting to configure SASL authentication per Kafka client. This enables running multiple Kafka clients with different (or the same) SASL configurations in a single JVM.
To do so:
Unset java.security.auth.login.config
In each Kafka client properties add sasl.jaas.config. For example:
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required \
username="myClusterUser" \
password="user-secret";
see http://kafka.apache.org/documentation.html#security_sasl_plain_clientconfig for the full details
MyKafkaClient.java
import org.apache.kafka.common.config.SaslConfigs;
private void init() {
properties.put(SaslConfigs.SASL_JAAS_CONFIG,
"org.apache.kafka.common.security.plain.PlainLoginModule required username=\"myClusterUser\" password=\"user-secret\"");
}
delete your JAAS file

Azure App Service is not able to connect to Azure Redis

I have a Java Spring application that i want to deploy on an Azure App Service that will connect to a Redis for Azure. I've already done it with the same application on a different subscription. I've created both the AppService and the Redis connection on Azure. I got the connection strings from Redis and i added to my Java Application, and also i've created a bean like follow:
#Bean
public JedisConnectionFactory connectionFactory() {
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
jedisConnectionFactory.setHostName(this.jedisHost);
if (this.jedisPassword != null && !this.jedisPassword.isEmpty()) {
jedisConnectionFactory.setPassword(this.jedisPassword);
}
jedisConnectionFactory.setPort(jedisPort);
jedisConnectionFactory.getPoolConfig().setMaxIdle(30);
jedisConnectionFactory.getPoolConfig().setMinIdle(10);
// jedisConnectionFactory.setUsePool(true);
return jedisConnectionFactory;
}
when i run the application in my local enviroment everything works fine. The application start and also can connect to Redis.
But when i deploy it on the azure cloud i get:
Caused by: java.net.SocketTimeoutException: connect timed out
JedisConnectionException: Failed connecting to host valuegoredis.redis.cache.windows.net:6380
JedisConnectionException: Could not get a resource from the pool
Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer'
I also had the same problems when running localy, but i added a firewall rule to include my IP.
I've also added the IP of the appService found by running nslookup .azurewebsite.net but here nothing changed.
I'm losing my mind trying to figure it out how can i make it works.
Edit: I've tried both jedis ports 6379 and 6380
The the blue circled are the IP of my app service and the red are my local IP
I'm allowing both SSL and no SSL connection on 6380 and 6379 but nothing seems to work

Redis with Java / Jedis Library Cold Standby Server

I am looking for a solution using Java and Redis (currently using the Jedis library) of having a cold standby redis server. I am looking for an intermediate solution to a single server, and a cluster of servers. Specifically, I want to have two servers setup, each standalone, and have my application only use the first Redis server if it is available, and fail over to the second server, only if the first server is not available - a standard cold standby scenario - no replication.
The current connection factory is setup as
public JedisConnectionFactory redisConnectionFactory() {
JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisUrl);
redisConnectionFactory.setPort(redisPort);
redisConnectionFactory.setDatabase(redisDbIndex);
return redisConnectionFactory;
}
where redisUrl resolves to something like 'my-redis-server.some-domain.com'. I would like to be able to specify the redis host name something like 'my-redis-server-1.some-domain.com,my-redis-server-2.some-domain.com' and have the second server used as the cold standby.

Weblogic jms distributed topic

Using java application, I'm trying to create a durable subscription on a jms uniform distributed topic.
The jms server is running on weblogic 10.3.5 and the topic is distributed on 2 servers.
If I'm developping a message driven bean, it's working. I have a durable subscription on both servers with the same subscription name.
With a standalone java application, I can do the job with a normal topic (not distributed). But can't manage it to work with distributed topic.
InitialContext ic = new InitialContext();
TopicConnectionFactory connectionFactory = (TopicConnectionFactory) ic.lookup("myConnectionFactory");
TopicConnection connection = connectionFactory.createTopicConnection();
connection.setClientID("testclient");
TopicSession session = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber;
Topic topic1 = (Topic) ic.lookup("jmsserver1#myTopic");
Topic topic2 = (Topic) ic.lookup("jmsserver2#myTopic");
subscriber = session.createDurableSubscriber(topic1,"testSubscription","",false);
subscriber = session.createDurableSubscriber(topic2,"testSubscription","",false);
Gives me
Exception in thread "main" weblogic.jms.common.JMSException: [JMSClientExceptions:055037]Subscription testSubscription is in use
In the weblogic console the first subscription testSubscription on myJmsModule!jmsserver1#myTopic is created not the second.
What can I do ?
You will have to remove the durable subscription manually and WLS will not remove to automatically
https://docs.oracle.com/cd/E17904_01/web.1111/e15493/dist_topics.htm#WLMDB10013
Setting Automatic Deletion of Durable Subscriptions :-
You can configure an MDB to automatically delete a durable topic subscription when the MDB is undeployed or deleted from a server. To configure an MDB to automatically delete durable topic subscriptions, set durable-subscription-deletion to True. By default, durable-subscription-deletion is set to False
By default it is false and thus it will not clear the durable subscriber automatically.
You need to change the ConnectionFactory via the weblogic admin console to create shareable connections
Client ID Policy: CLIENT_ID_POLICY_UNRESTRICTED
Subscription Sharing Policy:Sharable
https://docs.oracle.com/cd/E57014_01/wls/WLACH/pagehelp/JMSjmsconnectionjmsconnectionfactoryconfigclientparamstitle.html

Categories

Resources