Redis with Jpos

Skip to first unread message

arsalan fallah

Nov 4, 2021, 1:29:09 PM11/4/21
to jPOS Users
Hi everyone
 Does JPos have any Features for managing Redis in project ?
we have a Switching project for bank and this project wrote multi thread and it is managed with JPos  and  I want to save some values on Memory  .which solution do you purpose?

Alejandro Revilla

Nov 4, 2021, 1:35:26 PM11/4/21

A long time ago I wrote a PoC to use Redis with jPOS, using Jedis as a dependency.

I wrote a JedisService that you can initialize using a simple QBean descriptor like this:

<!-- deploy/05_jedis_service.xml -->
<jedis-service class="org.jpos.jedis.JedisService" logger="Q2">
   <property name="host" value="redishost" />
   <property name="port" value="6379" />
   <property name="timeout" value="120000" />
   <property name="ping-every" value="60000" />

I also wrote a JedisLogListener, that looks like this:

<!-- deploy/00_jedis_logger.xml -->
<logger name="JEDISLOG" class="org.jpos.q2.qbean.LoggerAdaptor">
 <log-listener class="org.jpos.util.JedisLogListener">
     <property name="jedis-queue" value="jCardLog" />

The JedisService QBean implementation was super simple:

package org.jpos.jedis;

import org.jpos.iso.ISOUtil;
import org.jpos.q2.QBeanSupport;
import org.jpos.util.NameRegistrar;
import org.jpos.util.Profiler;
import redis.clients.jedis.Jedis;

public class JedisService extends QBeanSupport implements Runnable {
   protected void initService() throws Exception {
       NameRegistrar.register(getName(), this);
   protected void startService() throws Exception {
       if (cfg.getLong("ping-every", 0L) > 0L)
           new Thread(this, getName()).start();
   protected void stopService() throws Exception {
   public Jedis getConnection()
  getLog().info("getting a new jedis connection");
  Jedis jedis = new Jedis(
               cfg.get("host", "localhost"),
               cfg.getInt("port", 6379),
               cfg.getInt("timeout", 120000)) ;
  return jedis;
   public void run() {
       while (running()) {
           try {
               Profiler prof = new Profiler();
               Jedis jedis = getConnection();
               getLog().info("PING", prof);
          } catch (Exception e) {
           ISOUtil.sleep(cfg.getLong("ping", 60000L));

as well as the JedisLogListener:

package org.jpos.util;

import org.jpos.core.Configurable;
import org.jpos.core.Configuration;
import org.jpos.core.ConfigurationException;
import org.jpos.iso.ISOUtil;
import org.jpos.jedis.JedisService;
import redis.clients.jedis.Jedis;

public class JedisLogListener implements Configurable, LogListener, Runnable {
   String jedisService;
   String jedisQueue;
   Space sp = SpaceFactory.getSpace();
   public static final long BUFFER_TIMEOUT = 300000L;
   public static final long RELAX = 1000L;

   public LogEvent log(LogEvent logEvent) {
       sp.out(jedisQueue, new FrozenLogEvent(logEvent), BUFFER_TIMEOUT);
       return logEvent;
   public void setConfiguration(Configuration cfg) throws ConfigurationException {
       jedisService = cfg.get("jedis-service", "jedis-service");
       jedisQueue = cfg.get("jedis-queue", null);
       if (jedisQueue == null)
           throw new ConfigurationException("jedis-queue property not configured");
       if (jedisService == null)
           throw new ConfigurationException("jedis-service property not configured");
       new Thread(this, "JedisLogger:" + jedisService + ":" + jedisQueue).start();
   public void run() {
       for (int i=0;;) {
           try {
               JedisService js = (JedisService) NameRegistrar.getIfExists(jedisService);
               if (js == null) {
                   if (i++ > 60)
                       throw new NameRegistrar.NotFoundException(jedisService + " not found");
               FrozenLogEvent evt = (FrozenLogEvent) sp.rd(jedisQueue, 5000L);
               if (evt != null) {
                   Jedis jedis = js.getConnection();
                   jedis.rpush(jedisQueue, evt.toString());
          } catch (Exception e) {
               Log.getLog("Q2", "jedis-log-listener").error(e);
               ISOUtil.sleep(RELAX); // take it easy on errors

Hope this gives you some pointers.

jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact:
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Victor Salaman

Nov 4, 2021, 1:35:38 PM11/4/21
to 'Ruchira Biyani' via jPOS Users
You can always use Jedis, and talk to Redis yourself. Redis is one of those you can't really do a general purpose integration, it is meant for specific use-cases that unfortunately are solution-specific. Try Jedis, use it, trust me the integration will probably take you a day or so.


Reply all
Reply to author
0 new messages