当前位置: 首页>>代码示例>>Java>>正文


Java JedisPubSub类代码示例

本文整理汇总了Java中redis.clients.jedis.JedisPubSub的典型用法代码示例。如果您正苦于以下问题:Java JedisPubSub类的具体用法?Java JedisPubSub怎么用?Java JedisPubSub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JedisPubSub类属于redis.clients.jedis包,在下文中一共展示了JedisPubSub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MessageConsumerRedisImpl

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
/**
 *
 * @param redisConnection redis 连接类
 * @param channels 订阅的频道列表
 */
public MessageConsumerRedisImpl(RedisConnection redisConnection, String[] channels) {
    Jedis jedis = null;
    try {
        if (channels != null && channels.length > 0) {
            jedis = redisConnection.getJedis();
            jedis.subscribe(new JedisPubSub() {
                @Override
                public void onMessage(String channel, String message) {
                    System.out.println("receive " + message + " from " + channel);
                    handleMessage(message);
                }
            }, channels);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
}
 
开发者ID:gaochao2000,项目名称:redis_util,代码行数:27,代码来源:MessageConsumerRedisImpl.java

示例2: pubSubNumPat

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
@Test
public void pubSubNumPat() {
  jedis.psubscribe(new JedisPubSub() {
    private int count = 0;

    @Override
    public void onPSubscribe(String pattern, int subscribedChannels) {
      count++;
      if (count == 3) {
        Jedis otherJedis = createJedis();
        Long numPatterns = otherJedis.pubsubNumPat();
        assertEquals(new Long(2l), numPatterns);
        punsubscribe();
      }
    }

  }, "test*", "test*", "chan*");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:19,代码来源:PublishSubscribeCommandsTest.java

示例3: pubSubChannels

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
@Test
public void pubSubChannels() {
  final List<String> expectedActiveChannels = Arrays
      .asList("testchan1", "testchan2", "testchan3");
  jedis.subscribe(new JedisPubSub() {
    private int count = 0;

    @Override
    public void onSubscribe(String channel, int subscribedChannels) {
      count++;
      // All channels are subscribed
      if (count == 3) {
        Jedis otherJedis = createJedis();
        List<String> activeChannels = otherJedis.pubsubChannels("test*");
        assertTrue(expectedActiveChannels.containsAll(activeChannels));
        unsubscribe();
      }
    }
  }, "testchan1", "testchan2", "testchan3");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:PublishSubscribeCommandsTest.java

示例4: pubSubNumSub

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
@Test
public void pubSubNumSub() {
  final Map<String, String> expectedNumSub = new HashMap<String, String>();
  expectedNumSub.put("testchannel2", "1");
  expectedNumSub.put("testchannel1", "1");
  jedis.subscribe(new JedisPubSub() {
    private int count = 0;

    @Override
    public void onSubscribe(String channel, int subscribedChannels) {
      count++;
      if (count == 2) {
        Jedis otherJedis = createJedis();
        Map<String, String> numSub = otherJedis.pubsubNumSub("testchannel1", "testchannel2");
        assertEquals(expectedNumSub, numSub);
        unsubscribe();
      }
    }
  }, "testchannel1", "testchannel2");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:PublishSubscribeCommandsTest.java

示例5: subscribe

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
public void subscribe(JedisPubSub jedisPubSub, String channel) {
    Collection<JedisPool> poolCollection = jedisCluster.getClusterNodes().values();
    Iterator iterator = poolCollection.iterator();

    while(iterator.hasNext()) {
        JedisPool jedisPool = (JedisPool)iterator.next();
        Jedis jedis = null;

        try {
            jedis = jedisPool.getResource();
            jedis.subscribe(jedisPubSub, new String[]{channel});
        } catch (Exception var11) {
            throw new RuntimeException(var11);
        } finally {
            jedisPool.returnResourceObject(jedis);
        }
    }

}
 
开发者ID:bitstd,项目名称:bitstd,代码行数:20,代码来源:RedisCacheWithCluster.java

示例6: startSubscribe

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
public void startSubscribe() {

        // 支持短线重连
        new Thread(() -> {
            while (true) {
                try {
                    Jedis jedisSub = this.createJedis();
                    jedisSub.psubscribe(new JedisPubSub() {
                        public void onPMessage(String pattern, String channel, String message) {
                            vertx.eventBus().publish(channel, message);
                        }
                    }, "*");
                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        Thread.sleep(1000l);
                    } catch (InterruptedException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }, "vertx-jedis-pubsub").start();
    }
 
开发者ID:kuangcao,项目名称:ninja-vertx-standalone,代码行数:24,代码来源:PubSub.java

示例7: createSubscriptionListener

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
private void createSubscriptionListener() {
    subscriptions = new JedisPubSub() {
        @Override
        public void onMessage(String channel, String message) {
            Collection<Function<byte[], Boolean>> currentActions = actionMap.get(channel);
            if(currentActions != null) {
                for(Function<byte[], Boolean> currentAction : currentActions) {
                    if(!currentAction.apply(toStringCodex.decode(message))) {
                        log.warning("attempt to not ack " + channel + " however this is not supported");
                    }
                }
            }

        }
    };
}
 
开发者ID:miniature-queue,项目名称:miniature-queue,代码行数:17,代码来源:JedisServerImplementation.java

示例8: init

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
@PostConstruct
public void init() {
    new Thread() {
        @Override
        public void run() {
            redisDao.subscribe(new JedisPubSub() {
                @Override
                public void onMessage(String pchannel, String message) {
                    logger.info("redis通知,channel={},message={}", pchannel, message);
                    if (channel.equals(pchannel)) {
                        updateCache();
                    }
                }
            }, channel);
        }
    }.start();

    updateCache();
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:20,代码来源:ConfigService.java

示例9: setupPubSub

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
private JedisPubSub setupPubSub() {
    final JedisPubSub jedisPubSub = new JedisPubSub() {
        @Override
        public void onMessage(String channel, String message) {
            RedisSubscriber.this.onMessage(channel, message);
        }
    };
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Jedis jedis = SimpleAPI.getInstance().getManager(RedisManager.class).getRedisPool().getResource();
                jedis.subscribe(jedisPubSub, channel);
                jedis.quit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, "subscriberThread").start();
    SimpleAPI.getInstance().addOnDisable(() -> jedisPubSub.unsubscribe());
    return jedisPubSub;
}
 
开发者ID:toonsevrin,项目名称:SimpleAPI,代码行数:23,代码来源:RedisSubscriber.java

示例10: run

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
@SuppressWarnings("static-access")
@Override
public void run() {
	Thread.currentThread().setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
		@Override
		public void uncaughtException(Thread arg0, Throwable arg1) {
			logger.error("[error]{}:{}",slaveRedis.getIp(), slaveRedis.getPort(), arg1);
			Cat.logError(arg1);
			redisStatCheckResult.put(slaveRedis, Boolean.FALSE);
			if (null != slave) {
				slave.close();
			}
		}
	});

	logger.debug("[Psubscribe]{}:{}", slaveRedis.getIp(), slaveRedis.getPort());
	slave.psubscribe(new JedisPubSub() {
		@Override
		public void onPMessage(String pattern, String channel, String msg) {
			logger.debug("[OnPMessage]{}:{}", slaveRedis.getIp(), slaveRedis.getPort());
			redisStatCheckResult.put(slaveRedis, Boolean.TRUE);
		}
	}, generateURL(masterRedis.getIp(), masterRedis.getPort()));
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:25,代码来源:StandaloneStatMonitor.java

示例11: subscribe

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
public void subscribe(final JedisPubSub jedisPubSub, final String... channels) {
    if (cluster) {
        jedisCluster.subscribe(jedisPubSub, channels);
    } else {
        jedisOperator.subscribe(jedisPubSub, channels);
    }
}
 
开发者ID:yrain,项目名称:smart-cache,代码行数:8,代码来源:JedisTemplate.java

示例12: subscribe

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
public void subscribe(final JedisPubSub jedisPubSub, final String... channels) {
    execute(new JedisExecutor<Void>() {
        @Override
        Void doInJedis(Jedis jedis) {
            jedis.subscribe(jedisPubSub, channels);
            return null;
        }
    });
}
 
开发者ID:yrain,项目名称:smart-cache,代码行数:10,代码来源:JedisOperator.java

示例13: startSubscribe

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
/**
 * <message_type xmlns="message:extension"><type>groupChat</type></message_type>
 */
private void startSubscribe() {
  String type = "pushType";
  String msg = "message";
  String allType = "all";
  String listType = "list";
  getJedis().subscribe(new JedisPubSub() {
    @Override public void onMessage(String channel, String message) {
      super.onMessage(channel, message);
      System.out.println("得到消息为:" + message);
      TigPubsub pubsub = new Gson().fromJson(message,TigPubsub.class);
      try {
        pubSubRepository.insertPubsubMessage(pubsub);
        if (pubsub.getPushType().equals(allType)) {
          List<BareJID> users = userRepository.getUsers();
          System.out.println("打印出所有的用户" + users.size());
          for (BareJID user : users) {
            Packet push_message = Message.getMessage(JID.jidInstance(
                "[email protected]" + DISCO_DESCRIPTION + "." + "dc-a4b8eb92-xmpp.jiangtao.tech."),
                JID.jidInstance(user.toString()),
                StanzaType.chat, pubsub.getMessage(), null, null, null);
            Element event =
                new Element(MESSAGE_SENDER, new String[] {"xmlns"},
                    new String[] {SENDER_EXTENSION});
            event.addChild(new Element(TYPE, "push"));
            //需要加上sender,发送者是谁
            push_message.getElement().removeChild(event);
            push_message.getElement().addChild(event);
            System.out.println(push_message.toString());
            addOutPacket(push_message);
          }
        }else if (pubsub.getPushType().equals(listType)){
          log.log(Level.SEVERE,"针对单个或者多个用户,但不是全部用户....");
        }
      } catch (TigaseDBException | TigaseStringprepException e) {
        e.printStackTrace();
      }
    }
  }, channel);
}
 
开发者ID:BosCattle,项目名称:PushServer,代码行数:43,代码来源:PushServiceComponent.java

示例14: subscribe

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
@Override
public void subscribe(JedisPubSub jedisPubSub, String... channels) {
  Span span = helper.buildSpan("subscribe");
  span.setTag("channels", Arrays.toString(channels));
  try {
    super.subscribe(jedisPubSub, channels);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-redis-client,代码行数:14,代码来源:TracingJedisCluster.java

示例15: psubscribe

import redis.clients.jedis.JedisPubSub; //导入依赖的package包/类
@Override
public void psubscribe(JedisPubSub jedisPubSub, String... patterns) {
  Span span = helper.buildSpan("psubscribe");
  span.setTag("patterns", Arrays.toString(patterns));
  try {
    super.psubscribe(jedisPubSub, patterns);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-redis-client,代码行数:14,代码来源:TracingJedisCluster.java


注:本文中的redis.clients.jedis.JedisPubSub类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。