简体   繁体   中英

OSGi Redis Shared Pool Configuration

I am using below configuration for connecting to redis using jedis client. I would like to create OSGi shared pool service, so that it will be exported and used in other bundles. Please let me know how to do that.

<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxActive" value="200" />
    <property name="maxIdle" value="50" />
    <property name="maxWait" value="3000" />
    <property name="testOnBorrow" value="${jedis.testOnBorrow}" />
</bean>

<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
    <constructor-arg index="0" ref="jedisPoolConfig" />
    <constructor-arg index="1" value="${jedis.host}" />
    <constructor-arg index="2" value="${jedis.port}" />
</bean>

Looking at the API docs, JedisPool doesn't use a supporting interface so you would need to roll your own that defines exactly what operations your applications need to share. Then create a concrete base class that either extends or encapsulates your JedisPool instance and export it as an OSGi service.

Depending on the dependency injection API you are using in your snippet above, there are simple service export elements for both Spring DM and Blueprint that will simplify the exporting of the OSGi service part so you can focus on the interface and the supporting POJO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM