本文整理汇总了Java中org.springframework.data.redis.connection.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于org.springframework.data.redis.connection包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PerSubscriptionListenerAdapter
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
public PerSubscriptionListenerAdapter(ChannelHandlerContext context, String subId, String listenerId) {
this.context = context;
this.setDelegate(new MessageListener() {
@Override
public void onMessage(Message message, byte[] pattern) {
LOGGER.trace("Subscription [{}] received redis channel message [{}]", listenerId, message);
final String channel = new String(message.getChannel())
.substring(properties.getRedisChannelPrefix().length());
final byte[] body = message.getBody();
final DefaultStompFrame messageFrame = new DefaultStompFrame(StompCommand.MESSAGE);
messageFrame.headers().add(StompHeaders.SUBSCRIPTION, subId);
messageFrame.headers().add(StompHeaders.MESSAGE_ID, Integer.toString(messageId.getAndIncrement()));
messageFrame.headers().add(StompHeaders.DESTINATION, properties.getChannelPrefix() + channel);
messageFrame.headers().add(StompHeaders.CONTENT_TYPE, properties.getContentType());
messageFrame.headers().addInt(StompHeaders.CONTENT_LENGTH, body.length);
messageFrame.content().writeBytes(body);
context.writeAndFlush(messageFrame);
}
});
}
示例2: receive
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
/**
* Receive message from subscribed channel.
*
* @param message
* Message.
* @param pattern
* Channel name pattern that let us receive the message.
*/
private void receive(Message message, byte[] pattern) {
try {
active.readLock().lock();
MDC.put("worker", getName());
String channel = channelDao.getChannel(message);
MDC.put("queue", channel);
Execution execution = channelDao.getExecution(message);
MDC.put("execution", Long.toString(execution.getId()));
MDC.put("job", execution.getJob().getClass().getSimpleName());
process(channel, execution);
} catch (Throwable t) {
log.error("Uncaught exception in worker.", name, t);
eventBus.publishEvent(new WorkerError(this, t));
} finally {
active.readLock().unlock();
MDC.remove("job");
MDC.remove("execution");
MDC.remove("queue");
MDC.remove("worker");
}
}
示例3: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
/**
* 收到缓存过期消息时清除EhCache中的Session缓存
*/
@Override
public void onMessage(final @NotNull Message message, byte[] bytes) {
ShiroSessionMessage shiroSessionMessage =
new ShiroSessionMessage(message.getChannel(), message.getBody());
log.debug("channel {} , message {} ", shiroSessionMessage.getChannel(), shiroSessionMessage.msgBody);
sessionDao.unCache(shiroSessionMessage.msgBody.sessionId);
}
示例4: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@Override
public void onMessage(Message message, byte[] pattern) {
byte[] messageChannel = message.getChannel();
byte[] messageBody = message.getBody();
if (messageChannel == null || messageBody == null) {
return;
}
String channel = new String(messageChannel);
if (!channel.contains(REDIS_KEY_WORD)) {
return;
}
String body = new String(messageBody);
if (!body.startsWith(REDIS_KEY_PREFIX)) {
return;
}
String[] temp = StringUtils.split(body, REDIS_KEY_SEPARATOR);
String type = temp[1], key = temp[2];
RedisEventHandler handler = RedisEventUtils.getRedisEventHandler(type);
Serializable id = handler.resolveKey(key);
if (id == null) {
return;
}
if (logger.isDebugEnabled()) {
logger.debug("Publishing Event for order " + id);
}
publishEvent(new RedisEvent(this, id, handler.getEventType()));
}
示例5: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@Override
public void onMessage(Message message, byte[] bytes) {
String jsonStr = WebmagicService.getString(message.getBody());
ContentBean contentBean = JSONObject.parseObject(jsonStr, ContentBean.class);
redisTemplate.execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection redisConnection) throws DataAccessException {
byte[] key = getByte(TIEBA_CONTENT_NO_IMAGE_KEY + contentBean.getName());
redisConnection.sAdd(key, getByte(contentBean.getId()));
return null;
}
});
}
示例6: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@Override
public void onMessage(Message message, byte[] pattern) {
try {
Exchange exchange = getEndpoint().createExchange();
setChannel(exchange, message.getChannel());
setPattern(exchange, pattern);
setBody(exchange, message.getBody());
getProcessor().process(exchange);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: registerExpiredEventListener
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@PostConstruct
private void registerExpiredEventListener() {
expiredListener = new MessageListener() {
@Override
public void onMessage(Message message, byte[] pattern) {
byte[] body = message.getBody();
if (body == null) {
return;
}
String key;
try {
key = new String(message.getBody(), "UTF-8");
} catch (UnsupportedEncodingException e) {
LOGGER.debug(() -> "failed to decode message body: " + bytesToHex(body), e);
return;
}
if (!key.startsWith(PREFIX_EXPIRE)) {
return;
}
String accessToken = key.substring(PREFIX_EXPIRE.length());
template.delete(keyAccessToken(accessToken));
Map<String, String> values = hashOps.entries(keyAccessToken(accessToken));
if (values != null && !values.isEmpty()) {
setOps.remove(keyClientToken(values.get(KEY_CLIENT_TOKEN)), accessToken);
setOps.remove(keyAccount(values.get(KEY_OWNER)), accessToken);
}
}
};
container.addMessageListener(expiredListener, new PatternTopic("[email protected]*__:expired"));
}
示例8: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
public void onMessage(Message message, byte[] pattern) {
byte[] body = message.getBody();
byte[] channel = message.getChannel();
String content = redisTemplate.getStringSerializer().deserialize(body);
String publisher = redisTemplate.getStringSerializer().deserialize(channel);
System.out.println(publisher + ": " + content);
}
示例9: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
public void onMessage(final Message message, final byte[] pattern) {
messageList.add(message.toString());
System.out.println("Message received: " + new String(message.getBody()));
}
示例10: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@Override
public void onMessage(Message message, byte[] pattern) {
queue.produce(message.toString());
logger.info("Message received: " + message.toString());
}
示例11: getChannel
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@Override
public String getChannel(Message message) {
String channel = strings.deserialize(message.getChannel());
return channel.substring(channel.lastIndexOf(":") + 1);
}
示例12: getExecution
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@Override
public Execution getExecution(Message message) {
return executions.deserialize(message.getBody());
}
示例13: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
/**
* 所有帖子ID,部分帖子包含图片
* @param message
* @param bytes
*/
public void onMessage(Message message, byte[] bytes) {
try {
String jsonStr = WebmagicService.getString(message.getBody());
List<ContentBean> pageList = JSONObject.parseArray(jsonStr, ContentBean.class);
if (pageList != null && pageList.size() > 0) {
String tiebaName = pageList.get(0).getName();
//包含图片的key
byte[] imageKey = getByte(TIEBA_CONTENT_IMAGE_KEY + tiebaName);
//不包含图片的key
byte[] noImageKey = getByte(TieBaNoImageIdMessageListener.TIEBA_CONTENT_NO_IMAGE_KEY + tiebaName);
log.info("{}:待同步pageID数量:{}", tiebaName, pageList.size());
//可能包含图片的page
List<ContentBean> imagePageList = new ArrayList<>();
//没有被缓存的page
List<String> notCachePageImageList = new ArrayList<>();
removeExistId(pageList, imagePageList, notCachePageImageList, imageKey, noImageKey);
log.info("{}:去除已同步pageID后数量:{}", tiebaName, notCachePageImageList.size());
//包含图片的map
ConcurrentHashMap<byte[], byte[]> map = contentImageProcessor.start(notCachePageImageList, tiebaName);
redisTemplate.executePipelined(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection redisConnection) throws DataAccessException {
//保存所有帖子 tieba_content_image_4813146001
if (map.size() > 0)
redisConnection.mSet(map);
// 存储帖子最新更新时间
byte[] timeKey = getByte(TIEBA_CONTENT_UPDATE_TIME_KEY + tiebaName);
//可能包含图片的
for (ContentBean contentBean : imagePageList) {
Set<String> set = CollectionUtils.convertMapByteToSetString(map);
//没有被缓存的
if (set.contains(TIEBA_CONTENT_IMAGE_KEY + contentBean.getId())) {
//key=tieba_content_image_李毅
redisConnection.sAdd(imageKey, WebmagicService.getByte(contentBean.getId()));
//key=tieba_content_image_4813146001
redisConnection.zAdd(timeKey, Double.parseDouble(contentBean.getDate()), WebmagicService.getByte(contentBean.getId()));
}
}
log.info("ScheduleTask.run={}", true);
return null;
}
});
}
}catch (Exception e){
log.error("onMessage error",e);
}finally {
ScheduleTask.run = true;
}
}
示例14: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void onMessage(Message message, byte[] pattern) {
byte[] messageChannel = message.getChannel();
byte[] messageBody = message.getBody();
String channel = new String(messageChannel);
if (channel.startsWith(getSessionCreatedChannelPrefix())) {
// TODO: is this thread safe?
Map<Object, Object> loaded = (Map<Object, Object>) this.defaultSerializer
.deserialize(message.getBody());
handleCreated(loaded, channel);
return;
}
String body = new String(messageBody);
if (!body.startsWith(getExpiredKeyPrefix())) {
return;
}
boolean isDeleted = channel.endsWith(":del");
if (isDeleted || channel.endsWith(":expired")) {
int beginIndex = body.lastIndexOf(":") + 1;
int endIndex = body.length();
String sessionId = body.substring(beginIndex, endIndex);
RedisSession session = getSession(sessionId, true);
if (session == null) {
logger.warn("Unable to publish SessionDestroyedEvent for session "
+ sessionId);
return;
}
if (logger.isDebugEnabled()) {
logger.debug("Publishing SessionDestroyedEvent for session " + sessionId);
}
cleanupPrincipalIndex(session);
if (isDeleted) {
handleDeleted(session);
}
else {
handleExpired(session);
}
}
}
示例15: onMessage
import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@Override
public void onMessage(Message message, byte[] pattern) {
LOGGER.info("Message Received on channel " + new String(message.getChannel()) + " message :: " + message.toString() );
}