Stream-Hub send message to specific client - java

Hello im fairly new to the comet and reverse ajax scene. I discovered stream-hub and it seems very useful.
Reading the documentaions and examples I cant find a way for the server to send a message to a specific client.
I only found the
publish(String topic, Payload payload)
method that broadcast to all users subscribe to the topic
This is what I want EX:
There is 3 users connected User A, User B, and User C
User A sends a message, server receives message and sends to User C, but not User B.
Any ideas?

Related

Spring WebSocket: Order of subscriptions don't allow messages to be received

I followed the https://spring.io/guides/gs/messaging-stomp-websocket/ and added a few modifications (mainly Spring Security Auth and dynamic topics(Rooms)).
The order the client subscribes to topics doesn't allow messages onDisconnect event to be received by the client that's still in the room despite the server sysout showing that it sends.
I have 2 topics that the client subscribes to in a room and this order of subscriptions works but if I change the order of the subscriptions then the user that's still in the room won't receive a message:
// user direct message
stompClient.subscribe(`/user/topic/${roomId}`, (message) => {...}
// General
stompClient.subscribe(`/topic/${roomId}`, (message) => {...}
2 users connect and I send alerts to the client that the users joined and all is well until 1 client disconnects. In the order of subscriptions above the client that's still in the room will receive the message that a client has disconnected but if the subscription order is changed then the client will not receive the message that a client disconnected.
Does the order in how the client subscribes to topics matter?

Getting reply to a particular sms sent pragmatically from app

I'm working on an app that requires to read the reply of a particular sms message sent and update the Database, i know i can use SmsManager (Pending Intent) class to know the status of the message (Like SENT or DELIVERED) and also broadcast receiver for receiving sms but i want to be able to read the user reply to that sms.
There can be multiple message sent at a particular time which i want to be able to differentiate between response for each sms.
Is there a way to attach something like an id to sms and get it back when i receive the reply or how can i achieve this? most of the tutorials online only cover how to listen to the status and how to receive new sms.

Can two consumers get same set of messages while retrieving messages using an Pull based Manner?

So I have a one client-server based ecosystem where I am using RabbitMQ as a persistent Middleware.
Now the flow of a single message goes like this.
Step-1: Client A sends a message to the server with the destination
being set to Client B in the metadata of that message.
Step-2: Server upon receiving a message pushes the message to the
RabbitMQ and sends Client B a notification that he has some messages
to fetch.
Step-3: Client B upon getting notified calls the fetch message API to
get messages from the server.
Step-4: On the server, after getting called from the Client B pulls
messages from the RabbitMQ using the pull-based approach
(channel.basicGet(queueName, false)) and hands over the list of
messages.
Now in the above flow, there are few things that I have some doubt with.
First of all, if my client receives two notifications and calls the pull message API twice, there might be a concurrency problem.
Suppose I am not sending the message Acknowledgement while getting the message but I am sending afterwards, then can It be possible that the same message being sent to two pull API? If so is there any way to prevent this from happening?
Sample Code to Get Message From the MQ:
long currentMessageCount = channel.messageCount(QUEUE_NAME);
while (currentMessageCount-- > 0) {
GetResponse getResponse = channel.basicGet(QUEUE_NAME, false);
if (getResponse == null) {
break;
}
AMQP.BasicProperties props = getResponse.getProps();
Envelope envelope = getResponse.getEnvelope();
int messageCount = getResponse.getMessageCount();
byte[] body = getResponse.getBody();
/*
Do some logic
*/
channel.basicAck(envelope.getDeliveryTag(), false);
}
TIA
basicGet is rarely the correct solution. In Step 2, the client should be consuming from RabbitMQ. No notification that a message is ready is necessary. RabbitMQ will send the message to Client B as soon as it's in the queue. Step-3 and Step-4 become unnecessary.
NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.

exchange files between clients via socket

How I can send file from one client (A) to another one (B) via socket? and vice versa, send file from B to A. I mean that make the client sender and receiver at the same time.
In other word, when muticlient connect to server, how I distinguish between clients ?
You need to implement you own communication message format in short a simple protocol .
You keep a list of all active sockets in a shared list/map , and based on the request from the message you pick up the apt client and push the desired message to that.
You can implement the actual message format as you want, but this can be the blueprint.
In this case lets say your client A sends message : 1. Client Id 2. File Start 3 X . File Content 4. File End
as soon as you get a connection you get the target client id , the file start message lets you understand the next message just needs to be diverted to target and file End message defines the transfer complete.
Also, you may would like to send Acknowledgement message from server to client, in order to eradicate transfer issues.
It is good way to manage client using their id(i.e. a unique long or string or any other for each user). At the time of connection to socket client send their id , store that is in collection. And when a user(Client) want to send file send with own id and Id of that user(Client) want to send.

How does one send chat message from chat bot to clients?

I have made a bot which can reply when the client sends a message. I want to send a message to the client without them sending me a message. I don't want to code in each and every message. Can someone please suggest a method for this? Thank you.
XMPPService xmpps = XMPPServiceFactory.getXMPPService();
Message msg = xmpps.parseMessage(req);
.....
......
msg = new MessageBuilder()
.withRecipientJids(jid)
.withBody(respMsg)
.build();
xmpps.sendMessage(msg);
what the above code does is, it sends the message after it receives a message from the client. my bot basically informs the clients about important announcements. so suppose i want to tell them something important without them asking. i just want to send a message and all my clients should receive it. do i need the JID of my clients? if so, then how do i get them? i am new to xmpp please help me.
Thank you.
It is not possible to broadcast messages to all jou xmpp contacts at once. You have to adress them one by one. If you look deepher in the xmpp code you will see that status updates will be broadcasted to all contacts that are not offline. Maybe you can use that to your advantage.

Categories

Resources