Search in sources :

Example 6 with TransportException

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);
}
Also used : Client(io.transport.core.repository.Client) TransportException(io.transport.core.exception.TransportException)

Example 7 with TransportException

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);
}
Also used : Client(io.transport.core.repository.Client) TransportException(io.transport.core.exception.TransportException)

Example 8 with TransportException

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);
    }
}
Also used : Client(io.transport.core.repository.Client) TransportException(io.transport.core.exception.TransportException) TransportException(io.transport.core.exception.TransportException) TransportMessage(io.transport.core.protocol.message.internal.TransportMessage)

Aggregations

TransportException (io.transport.core.exception.TransportException)8 Client (io.transport.core.repository.Client)3 TransportMessage (io.transport.core.protocol.message.internal.TransportMessage)2 NodeInfo (io.transport.common.bean.NodeInfo)1 TransportAuthenticationException (io.transport.core.exception.TransportAuthenticationException)1 TransportConnectLimitException (io.transport.core.exception.TransportConnectLimitException)1 ConnectRespMessage (io.transport.core.protocol.message.internal.ConnectRespMessage)1 DeviceRegistRespMessage (io.transport.core.protocol.message.internal.DeviceRegistRespMessage)1