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


Java Message类代码示例

本文整理汇总了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);
                }
            });
        }
 
开发者ID:itzg,项目名称:redis-stomp-relay,代码行数:24,代码来源:SubscriptionManagement.java

示例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");
   }
}
 
开发者ID:shopping24,项目名称:redjob,代码行数:35,代码来源:ChannelWorker.java

示例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);
}
 
开发者ID:izhangzhihao,项目名称:Shiro-Session-Redis,代码行数:11,代码来源:ShiroSessionService.java

示例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()));
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:34,代码来源:RedisTimerListener.java

示例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;
		}
	});
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:14,代码来源:TieBaNoImageIdMessageListener.java

示例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);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:RedisConsumer.java

示例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"));
}
 
开发者ID:to2mbn,项目名称:authlib-agent,代码行数:35,代码来源:TokenRepositoryImpl.java

示例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);
}
 
开发者ID:irfen,项目名称:redis-example,代码行数:8,代码来源:RedisSubTest.java

示例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()));
}
 
开发者ID:michaelcgood,项目名称:spring-data-redis-example,代码行数:5,代码来源:MessageSubscriber.java

示例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());
}
 
开发者ID:V-I-C-T-O-R,项目名称:DataM,代码行数:6,代码来源:RedisInfoSubscriber.java

示例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);
}
 
开发者ID:shopping24,项目名称:redjob,代码行数:6,代码来源:ChannelDaoImpl.java

示例12: getExecution

import org.springframework.data.redis.connection.Message; //导入依赖的package包/类
@Override
public Execution getExecution(Message message) {
   return executions.deserialize(message.getBody());
}
 
开发者ID:shopping24,项目名称:redjob,代码行数:5,代码来源:ChannelDaoImpl.java

示例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;
	}
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:55,代码来源:TieBaImageIdMessageListener.java

示例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);
		}
	}
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:50,代码来源:RedisOperationsSessionRepository.java

示例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() );
}
 
开发者ID:omanand,项目名称:spring-data-redis-demo,代码行数:5,代码来源:RedisMessageSubscriber.java


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