Firebase publisher subscriber - java

Firebase If subscriber is subscribed to a topic before publisher subscribes and pushes to the topic , can Firebase deliver message to subscriber after publisher pushes message ?
In my app I have a scenario where if subscriber subscribes to a topic first before publisher adds to that topic and sends message , I should be able to send that message to initially added subscriber.

If i understand well your request, according to the documentation, the messages sent to a topic are received only after the device has suscribed. So, it doesn't receive messages that were sent to the topic when it isn't subscribed.
Also:
Client apps can subscribe to any existing topic, or they can create a
new topic. When a client app subscribes to a new topic name (one that
does not already exist for your Firebase project), a new topic of that
name is created in FCM and any client can subsequently subscribe to
it.

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?

How to send websocket message to a specific subscription in a session?

I have implemented a WebSocket server using Spring WebSocket and STOMP. There are multiple subscriptions over a single session and I want to send message to a specific subscription only.
Steps to reproduce:
Client connects to server by calling registered STOMP endpoint.
Client makes 2 subscription over the connection.
SUBSCRIBE
country:germany
id:sub-0
destination:/user/queue/countryUpdates
SUBSCRIBE
country:france
id:sub-1
destination:/user/queue/countryUpdates
In SimpUserRegistry there is 1 user and 1 session with 2 subscription.
Problem is if I send a message to one subscription it's send to other subscription as well.
At the time of sending the message I am adding subscription id in native headers, but it's not working.
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
accessor.setNativeHeader("id", subscriptionId);
accessor.setNativeHeader("subscription", subscriptionId);
accessor.setSubscriptionId(subscriptionId);
accessor.setLeaveMutable(true);
messagingTemplate.convertAndSendToUser(simpUserId, REPLY_DESTINATION, message, accessor.getMessageHeaders());
What I've tried: If I add country to destination, each subscription have unique destination than there are no duplicate messages.
I want to use id/subscriptionId to determine the subscription and send message to that particular subscription.

Conditional logic on flux of messages from reactor-kafka

I need to process flux of message from kafka topic using reactor-kafka. What should I achieve are these steps:
Read messages from kafka topic as flux.
Try to send each message to external system.
In case of success log that event, in case of failure - send message to another topic.
Manually acknowledge processed messages (important: in order).
I've found in docs example of building reactive pipeline (just receiving message from one topic and sending it to another) with manual acknowledgement of messages:
sender.send(KafkaReceiver.create(receiverOptions)
.receive()
.map(m -> SenderRecord.create(transform(m.value()), m.receiverOffset())))
.doOnNext(m -> m.correlationMetadata().acknowledge());
But how can I send to another topic one part of processed messages and skip another part, but in the end make acknowledgements for all processed messages in order?

How to save messages and Topics in Activemq?

I have a Queue and Topic with 2 messages in Activemq.If I restart Activemq.I am losing messages and also Topic.
Even If I restart Activemq,I don't want to lose any messages from any Topicand Queue.Is it possible.
I am using Activemq 5.8.0.
A producer produces the message and send it to the Topic, which ever
consumer is running at that point of time, will receive the message.
If you want consumer which is not up now, but might be running in
future to get this message, you will have to tell the Broker to
persist the message and store the information that this perticular
consumer has not received the message.
If you have working code with-out durable subscriber, you will have to do the following changes.
In the consumer,
1. set the clinetId. Because Topic should know which consumer is yet to receive the message. Or has received the message.
Connection.setClientID(String)
2. Should be creating a durable subscriber for your topic
Connection.createDurableSubscriber()
3. Add your listener to this subscriber.
subscriber.setMessageListener(yourlistener)
4. Once you receive the message, you will have to acknowledge it
This link shows how it is done: But its in c# i guess.
http://myadventuresincoding.wordpress.com/2011/08/16/jms-how-to-setup-a-durablesubscriber-with-a-messagelistener-using-activemq/
Read these links for more info :
http://activemq.apache.org/how-do-durable-queues-and-topics-work.html
http://activemq.apache.org/why-do-i-not-receive-messages-on-my-durable-topic-subscription.html
http://activemq.apache.org/manage-durable-subscribers.html

How to receive acknowledgement in JMS

Here's my scenario. The program is developed with publisher/subscriber methodology. Have two topics (topic1, topic2) in producer and consumer part. I need to get the acknowledgement of the received topic1 from consumer in producer program so that when the acknowledgement status is true, the producer program will have to send the message on topic2.
Had googled links suggesting session.CLIENT_ACKNOWLEDGE in consumer. But I'm in need of the Acknowledgement status to be returned to producer for further process.
JMS specification does not define any API for a publisher to know if a message was consumed by a subscriber or not. A publisher just publishes a message and it is the messaging provider/broker to deliver that message to subscriber. A broker will deliver the message if there is a subscription otherwise that message is discarded.
The session.CLIENT_ACKNOWLEDGE option is one of the way a consumer tells a messaging provider (not producer) to remove the message from it's queue/memory. There are couple of other acknowledgement options as well but all these options are for telling a messaging provider to remove the message but not telling a producer.
If producer requires an acknowledgement from a consumer, then consumer will have to publish an acknowledgement message on another topic and producer subscribes to that topic to receive those acknowledgements. For example:
Producer publishes on TOPIC1
Producer subscribes to TOPIC1/ACKS
Consumer subscribes to TOPIC1
After receiving a message
Consumer publishes an acknowledgement message to TOPIC1/ACKS
Producer will receive the acknowledgement message.
It can then publish on TOPIC2
You must note that there can be multiple acknowledgement messages as there can be more than one subscribers on TOPIC1.
If your program contains only one message producer, you can create a Queue in the message consumer and let the producer subscribe to that Queue. In the Queue mode, it's point-to-point. So the message will only be delivered from the consumer to the producer.
Alternatively, you can also use setJMSReplyTo method to specify the Queue you want the consumer reply to when it receives the message from the producer. This way you don't need to create the Queue explicitly in the consumer but you can create the Queue in the producer as well. But you still need to let the producer listen to that Queue to received the acknowledgement.

Categories

Resources