@Override public boolean isClosed() { return delegate.isClosed(); }
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { RedisCommand commandToExecute = RedisCommand.failsafeCommandLookup(method.getName()); if (isPotentiallyThreadBoundCommand(commandToExecute)) { if (log.isDebugEnabled()) { log.debug(String.format("Invoke '%s' on bound conneciton", method.getName())); } return invoke(method, obj, args); } if (log.isDebugEnabled()) { log.debug(String.format("Invoke '%s' on unbound conneciton", method.getName())); } RedisConnection connection = factory.getConnection(); try { return invoke(method, connection, args); } finally { // properly close the unbound connection after executing command if (!connection.isClosed()) { connection.close(); } } }
@Override public boolean isClosed() { return redisConnection.isClosed(); }
@Override public boolean isClosed() { return delegate.isClosed(); }
@Override public boolean isClosed() { return delegate.isClosed(); }
@Override protected void doResponse(String address, Consumer<String> consumer) { new Thread(() -> redisTemplate.execute((RedisCallback<Void>) connection -> { while (!connection.isClosed()) { List<byte[]> messages = connection.bRPop(30, address.getBytes()); if (messages == null) { continue; } String message = new String(messages.get(1), StandardCharsets.UTF_8); consumer.accept(message); } return null; })).start(); } }
@Override public void response(String address, Consumer<String> consumer) { new Thread(() -> redisTemplate.execute((RedisCallback<Void>) connection -> { try { while (!connection.isClosed()) { List<byte[]> messages = connection.bRPop(30, address.getBytes()); if (messages == null) { continue; } String message = new String(messages.get(1), "UTF-8"); logger.trace("[MQ] response {}:{}", address, message); consumer.accept(message); } } catch (Exception e) { logger.error("Redis Response error.", e); } return null; } )).start(); } }
@Override public void response(String address, Consumer<String> consumer) { new Thread(() -> { RedisConnection connection = null; try { connection = redisTemplate.getConnectionFactory().getConnection(); while (!connection.isClosed()) { List<byte[]> messages = connection.bRPop(30, address.getBytes()); if (messages == null) { continue; } String message = new String(messages.get(1), "UTF-8"); logger.trace("[MQ] response {}:{}", address, message); consumer.accept(message); } } catch (Exception e) { e.printStackTrace(); } finally { if (connection != null && !connection.isClosed()) { connection.close(); } } }).start(); }
@Override public void request(String address, String message) { logger.trace("[MQ] request {}:{}", address, message); RedisConnection connection = null; try { connection = redisTemplate.getConnectionFactory().getConnection(); connection.lPush(address.getBytes(), message.getBytes()); } finally { if (connection != null && !connection.isClosed()) { connection.close(); } } }
@Override public void publish(String topic, String message) { logger.trace("[MQ] publish {}:{}", topic, message); RedisConnection connection = null; try { connection = redisTemplate.getConnectionFactory().getConnection(); connection.publish(topic.getBytes(), message.getBytes()); } finally { if (connection != null && !connection.isClosed()) { connection.close(); } } }
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { RedisCommand commandToExecute = RedisCommand.failsafeCommandLookup(method.getName()); if (isPotentiallyThreadBoundCommand(commandToExecute)) { if (log.isDebugEnabled()) { log.debug(String.format("Invoke '%s' on bound conneciton", method.getName())); } return invoke(method, obj, args); } if (log.isDebugEnabled()) { log.debug(String.format("Invoke '%s' on unbound conneciton", method.getName())); } RedisConnection connection = factory.getConnection(); try { return invoke(method, connection, args); } finally { // properly close the unbound connection after executing command if (!connection.isClosed()) { connection.close(); } } }
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { RedisCommand commandToExecute = RedisCommand.failsafeCommandLookup(method.getName()); if (isPotentiallyThreadBoundCommand(commandToExecute)) { if (log.isDebugEnabled()) { log.debug(String.format("Invoke '%s' on bound conneciton", method.getName())); } return invoke(method, obj, args); } if (log.isDebugEnabled()) { log.debug(String.format("Invoke '%s' on unbound conneciton", method.getName())); } RedisConnection connection = factory.getConnection(); try { return invoke(method, connection, args); } finally { // properly close the unbound connection after executing command if (!connection.isClosed()) { connection.close(); } } }
@Override public void subscribe(String topic, Consumer<String> consumer) { RedisConnection connection = null; try { connection = redisTemplate.getConnectionFactory().getConnection(); connection.subscribe((message, pattern) -> { try { String msg = new String(message.getBody(), "UTF-8"); logger.trace("[MQ] subscribe {}:{}", topic, msg); consumer.accept(msg); } catch (Exception e) { e.printStackTrace(); } }, topic.getBytes()); } finally { if (connection != null && !connection.isClosed()) { connection.close(); } } }
} finally { if (!connection.isClosed()) { connection.close();