Expand my Community achievements bar.

could not find MessageClient for clientId in pushMessageToClients

Avatar

Level 2

Hello everybody. I was stuck with unpleasent problem using LCDS 2.5.1 and theirs messaging service. My aim is sending real time messages to particular client which already subscribed to the defined destination within java code. I have following situation:

at first here is my messaging-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<service id="message-service" class="flex.messaging.services.MessageService">
    <adapters>
        <adapter-definition id="messagingAdapter"
            class="com.thomsonreuters.gip.messaging.impl.MessagingAdapterImpl" />
    </adapters>
    <destination id="realTimeMessaging">
        <adapter ref="messagingAdapter" />
        <channels>
            <channel ref="channel-rtmp" />
        </channels>
    </destination>
</service>

i am already know id of client consumer and pass it like input argument (Set clientIds)

actual sending performing in following method:

    protected void sendMessageToClients(Object msgBody, Set clientIds) {
        log.debug("send message to clients [ids = " + clientIds + ", message = " + msgBody + "]");

        // obtain message service by means of message broker
        MessageBroker messageBroker = MessageBroker.getMessageBroker(null);
        MessageService messageService = (MessageService) messageBroker.getService("message-service");

        // create async message with provided message body

        AsyncMessage message = createMessage(msgBody);

        // There I can sure that my client id (clientIds) present in message service subscribers id
        System.out.println(messageService.getSubscriberIds(message, true)); // this statement prints client id in wich i want to send message

        // Now push message to the clients (actualy one client)
        messageService.pushMessageToClients(clientIds, message, false);
    }

and realy this code doese nothing, message is not recieved by expected user and in logs of lcds a can see following line:

[LCDS]02/19/2010 15:29:59.567 [DEBUG] [Service.Message] Warning: could not find MessageClient for clientId in pushMessageToClients: [F88813EC-AC0A-EF4D-136CAE2F50EC44EB]

But id F88813EC-AC0A-EF4D-136CAE2F50EC44EB was already printed by this statement System.out.println(messageService.getSubscriberIds(message, true));

What I have missed? Or where I should look to resolve this issue?

Please help me

2 Replies

Avatar

Level 2

Forgot to say. I am able to send message to all clients within following code:

public void sendMessageToAllClients(Object msgBody) {
        log.debug("send message to all clients: " + msgBody);
        AcknowledgeMessage acknowledgeMessage = MessageBroker.getMessageBroker(null).routeMessageToService(createMessage(msgBody),
                null);
        log.debug("result: " + acknowledgeMessage);
    }

In this case all currently subscribed users receiving message.

here is method which creates AsyncMessage

private AsyncMessage createMessage(Object msgBody) {
        AsyncMessage msg = new AsyncMessage();
        msg.setClientId(getServerId());
        msg.setTimestamp(System.currentTimeMillis());
        msg.setMessageId(UUIDUtils.createUUID(true));
        msg.setDestination(destination);
        msg.setBody(msgBody);
        return msg;
    }

And by the way I have my own custom adapter here is code:

public class MessagingAdapterImpl extends MessagingAdapter {
    private static final Log log = LogFactory.getLog(MessagingAdapterImpl.class);

    @Override
    public Object invoke(Message message) {
        log.debug("sending message " + ToStringBuilder.reflectionToString(message, ToStringStyle.SHORT_PREFIX_STYLE));
        MessageService msgService = (MessageService) getDestination().getService();
        msgService.pushMessageToClients(message, true);
        msgService.sendPushMessageFromPeer(message, true);
        return null;
    }

    @Override
    public Object manage(CommandMessage commandMessage) {
        if (CommandMessage.SUBSCRIBE_OPERATION == commandMessage.getOperation()) {
            log.debug("subsriber is registered [" + commandMessage.getClientId() + "]");
        }
        if (CommandMessage.UNSUBSCRIBE_OPERATION == commandMessage.getOperation()) {
            log.debug("subsriber is unregistered [" + commandMessage.getClientId() + "]");
        }
        return null;
    }


    @Override
    public boolean handlesSubscriptions() {
        return true;
    }
}

Avatar

Level 2

OMG. I am laughing on my self. The problem was in absolutely different place... So this code is works as well. You can use it as example...