I have built up a redis server, I want to know whether I can make spring-session use the existed redis server instead of embed its redis-server?
Yes Spring Session can and should use an existing Redis Server. This is the primary way to deploy to production. I have provided a few examples below:
Spring Boot
Taking the Spring Boot Sample and converting it to use an external Redis Server can be done by:
Removing the #EmbeddedRedisServer annotation
Configuring the Redis Server Location For example, you might provide the following properties in your application.properties:
spring.redis.host=example.com
spring.redis.password=secret
spring.redis.port=6379
Other Samples
The other samples are quite similar to use an external Redis instance. For example, to change the httpsession sample to use an external Redis:
Remove #EnableEmbeddedRedis
Update your RedisConnectionFactory Bean definition to point to your Redis server
For example:
#Bean
public JedisConnectionFactory connectionFactory() {
JedisConnectionFactory connection = new JedisConnectionFactory();
connection.setPort(6379);
connection.setHostName("example.com");
connection.setPassword("secret");
return connection;
}
Related
Basically I want to create a cluster of 5 nodes as of now but I can add or remove more nodes(at a later time maybe). So I don't want to provide static IPs as given in the documentation provided on their site.
How can I do so or what is the best approach possible for this scenario? Any feasible approach or initiative would be highly appreciable.
P.S. : I'm a bit new with Apache Ignite.
Please take a look at Evgenii answer here:
How to add a new host to existing Apache Ignite instance?
Also you can read the next articles:
https://apacheignite.readme.io/docs/tcpip-discovery
https://apacheignite.readme.io/docs/zookeeper-discovery
Apache Ignite uses DiscoverySpi for cluster node discovery. For a cluster with 10's of nodes, tcpDiscoverySPI could be used. tcpDiscoverySPI uses tcpDiscoveryIpFinder
to get the list of cluster nodes.
Apart from Static and Multicast, there are different ipfinder implementations that could be used. One such implementation is JDBC based ipfinder.
TcpDiscoverySpi spi = new TcpDiscoverySpi();
// Configure your DataSource.
DataSource someDs = MySampleDataSource(...);
TcpDiscoveryJdbcIpFinder ipFinder = new TcpDiscoveryJdbcIpFinder();
ipFinder.setDataSource(someDs);
spi.setIpFinder(ipFinder);
IgniteConfiguration cfg = new IgniteConfiguration();
// Override default discovery SPI.
cfg.setDiscoverySpi(spi);
// Start Ignite node.
Ignition.start(cfg);
If you go with this approach, each node on the start-up will register its own IP address in the metadata table. These table entries would be used for discovery. This way, you do not need to have static IP addresses in your configurations
Ignite configuration consists of Java objects (of type IgniteConfiguration, etc) so you can populate it with dynamically provided IPs in runtime before starting your nodes.
Use Zookeeper based discovery.
https://apacheignite.readme.io/docs/zookeeper-discovery
All,
I'm running a simple SpringBoot app in PCF using a Rabbit on-demand service. The auto reconfiguration of the ConnectionFactory for the internal Rabbit service works just fine.
However I need a list of all queues on the Rabbit host. AFAIK this is only available through a call to the Rabbit management plugin (a REST API), see RabbitManagementTemplate::getQueues. This class expects an http URI with credentials.
I know the URI+credentials are exposed through the vcap.service variables as "http_api_uri', but I wonder if there's a more elegant way to get an instance of RabbitManagentTemplate with Spring magic cloud connectors / auto reconfiguration instead of manually reading the env vars and writing custom bean config.
It seems the ConnectionFactory only knows about the AMQP interface, and cannot create a RabbitManagementTemplate?
Thanks!
Spring Cloud Connectors won't help you here. It doesn't support setting up RabbitManagementTemplate, only a ConnectionFactory.
You don't have to parse the env yourself, you can use the flattened properties that Boot provides such as vcap.services.rabbitmq.credentials.http_api_uri. But you'll need to configure a RabbitManagementTemplate yourself using those Boot properties.
I am trying to integrate AWS elasticache redis with spring boot application using spring-data-redis. Getting below exception when using a service.
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:191)
... 84 more
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused
at redis.clients.jedis.Connection.connect(Connection.java:164)
Using below code
#Bean
public RedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {
JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);
redisConnectionFactory.setHostName("AWS primary replication group endpoint");
redisConnectionFactory.setPort(6379);
redisConnectionFactory.setUsePool(true);
redisConnectionFactory.setTimeout(3600);
return redisConnectionFactory;
}
I am able to connect to AWS Redis from my EC2 instance where the service is deployed. Any sample code or steps would be really helpful.
Might be late to this party but it was my experience that declaring spring.redis.host in application.yml, application.properties or at the command-line as a -D argument were not respected by RedisProperties within RedisAutoConfiguration.
What ultimately worked for me was exporting an environment variable, like so
export SPRING_REDIS_HOST=...
before starting up a service that attempts to connect to ElastiCache.
I am trying to setup ElastiCache to use with a Java Application. I have based my setup based on this documentation:
https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/BestPractices.html
The EC2 instance where the Java (8) App runs is in a VPC.
I have tried an ElastiCache instance both in VPC and no VPC. However, I always got,
redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused
If I install Redis myself on an EC2 instance and connect to it, the app is able to connect to the Redis Cache!
I have setup proper authorization with Security-group from EC2 to Cache-Security but no luck. I just can't make the 'connection'. Any sample connection snippet would be really helpful.
Redis is setup this way in the APP Config:
#Bean
public JedisConnectionFactory redisConnectionFactory() {
JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(<cache-node>);
redisConnectionFactory.setPort(6397);
redisConnectionFactory.setUsePool(true);
redisConnectionFactory.setTimeout(3600);
return redisConnectionFactory;
}
The various versions:
Jedis- 2.6.2, Spring- 4.1.6, Spring-data-> 1.5.0
telnet redis-ip 6397
Determine if redis can be connected
redisConnectionFactory.setPort(6397);
should probably be
redisConnectionFactory.setPort(6379); //default redis port
I am using JBoss AS 6 with HornetQ 2.2.5 as JMS server and Integrated JMS & JMX with Spring.
I can create new Queue dynamically by using JMX calls from Spring (eg. createQueue(queuename, jndiName))). But JNDI lookup is not working for it, I've other Physical queue for which JNDI lookup is working fine.
code sample:
mBeanServerConnection.invoke(serverObjectName,
"createQueue", new String[] { "myQueue",
"/queue/myQueue"}, new String[] {
"java.lang.String", "java.lang.String" });
Do I need to configure anything explicitly for these?
Any suggestion is appreciated.
Thanks.
When you call the createQueue management operation, you are also sending the JNDI address the queue should be bound as a parameter.
I will all depend on what you are passing as a parameter.
Give me an example on how you are calling createQueue and I will be able to better assist you.