The easy road
Mar 7th
To doubt everything or to believe everything are two equally convenient solutions; both dispense with the necessity of reflection.
H. Pointcaré
links for 2011-02-21
Feb 21st
ActiveMQ issues update
Jan 27th
This is a follow up to a previous entry I made about problems experienced with ActiveMQ 5.
First, let’s get this out of the way: I get what open source is; I get that there are a LOT of people who invest a LOT of their personal time; I get that while these people are working hard, I’m climbing cliffs instead of helping them even though I have the capacity and knowledge to do so; I get that criticism isn’t cool, especially when voiced publicly; and I get that I can be abrasive :).
With that said, in the last couple of months, we’ve worked hard to give ActiveMQ an nth chance. Unfortunately to no avail. The good folks at ActiveMQ have mentioned that we may be the first to use ActiveMQ the way we are. There has been a lot of effort into debugging the problem and there may be light at the end of the tunnel, but a fix is most likely a ways off.
The good news (for us that is), is that we have decided to keep ActiveMQ but in single broker configurations. Obviously, this is far from ideal, but all our products are currently programmed and architected around the possibility of a broker being unavailable, so we’ll keep on programming in the safeguards. I repeat: ActiveMQ is awesome in a single broker or embedded scenario.
Extending Spring-Data to select a database index with Jedis pools
Jan 16th
We came up with a not so un-common use-case of wanting to setup a Jedis connection pool that would automatically select a given database index on each connection. A colleague and I were about to patch the Spring-Data source code (we are already running a patched version), but instead found a very elegant solution by digging in a bit more:
The problem
The spring-data org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory class offers no way to configure it to use a specific database. It defaults to database index 0 (in other words, does nothing on a new connection – so Redis automatically works on index 0).
Given that we will be running automated integration tests on a single Redis server instance, and that those tests will flush the database on each run (i.e.: select 2; flushdb), we needed an easy way to get a new connection factory instance that would first select the configured database index when a connection is created.
Without that database index selection, any integration tests running concurrently would flush or interfere with the data of the other running tests.
The solution
We simply extended the org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory class and overrode the fetchJedisConnector() protected method:
public class MyCustomJedisConnectionPoolFactory extends JedisConnectionFactory {
private static final int DEFAULT_REDIS_DATABASE_INDEX = 0;
private int databaseIndex = 0;
@Override
protected Jedis fetchJedisConnector() {
Jedis jedis = super.fetchJedisConnector();
if (this.databaseIndex != DEFAULT_REDIS_DATABASE_INDEX) {
jedis.select(this.databaseIndex);
}
return jedis;
}
public void setDatabaseIndex(int databaseIndex) {
this.databaseIndex = databaseIndex;
}
}
The if statement isn’t strictly necessary in the fetchJedisConnector() method, but given that most of the time we will be using the default database, it seemed like it was worth it.