use of io.transport.core.exception.TransportException in project transporter by wang4ever.
the class TransportProcessors method sentGroupMsg.
/**
* 向group.channel多个通道发送消息
*
* @param repository
* channel通道库
* @param toGroupId
* 客户端ID(标识唯一通道)
* @param buf
* transport二进制byte消息
*/
public static void sentGroupMsg(ChannelRepository repository, TransportMessage warp) {
String toGroupId = warp.getToGroupId();
Collection<Client> clients = repository.getClients(toGroupId);
if (clients == null || clients.isEmpty())
throw new TransportException("'" + toGroupId + "' without online devices.");
// 2.0 遍历发送
for (Client c : clients) sent(c, warp);
}
use of io.transport.core.exception.TransportException in project transporter by wang4ever.
the class TransportProcessors method sentMsg.
/**
* 向channel通道发送消息
*
* @param repository
* channel通道库
* @param toDeviceId
* 客户端ID(标识唯一通道)
* @param buf
* transport二进制byte消息
*/
public static void sentMsg(ChannelRepository repository, TransportMessage warp) {
String toDeviceId = warp.getToDeviceId();
Client c = repository.getClient(toDeviceId);
if (c == null)
throw new TransportException("Device '" + toDeviceId + "' offline.");
// 1.0 构建消息并发送
sent(c, warp);
}
use of io.transport.core.exception.TransportException in project transporter by wang4ever.
the class PushGroupTopicHandler method execute.
@Override
public void execute(String topic, byte[] payload) {
if (logger.isDebugEnabled())
logger.debug("Push.group handler on message: topic={}, payload={}", topic, ByteBufs.toString(payload));
try {
// 当使用MQTT broker转发时,topic包含clientId的信息(topic -> toGroupId).
String toGroupId = TopicType.getSubTopicAfter(topic);
TransportMessage message = TransportProcessors.build(payload);
// 发送给toGroupId下所有deviceId
Collection<Client> clients = this.channelRepository.getClients(toGroupId);
if (clients != null && !clients.isEmpty()) {
for (Client c : clients) {
// toDeviceId -> actorName
String actorName = this.config.getCtlDeviceIdActorPkey() + c.getDeviceInfo().getDeviceId();
this.actorManager.actorTell(actorName, message);
if (logger.isDebugEnabled())
logger.debug("MQTT.group消息传送(Actor). actorName={}", actorName);
}
} else
throw new TransportException("toGroupId=" + toGroupId + " clients is null.");
} catch (Exception e) {
if (e instanceof TransportException)
logger.error("MQTT.group消费传送(Actor)失败. {}", ExceptionUtils.getRootCauseMessage(e));
else
logger.error("MQTT.group消费传送(Actor)异常. ", e);
}
}
Aggregations