I'm using react native android and want to ask if there's any way to have mqtt connection with background service so that when the app closes I can still receive messages via mqtt?
I have not done this myself, but this should be somewhat possible. While I do not know if it is possible to leave a single connection open that will receive MQTT messages regardless if the app is running in the foreground, running in the background, or has run and closed, I do think that effect can be achieved.
Background tasks (run when the app is in the background or has been closed) do not always work cross-platform (mostly Android-only), and do not allow you to run on an event-based trigger like receiving an MQTT publish. For this reason, you will see my suggestions based on things like setInterval and checking for messages at a given point. Because the connection is not alive at all times, you will have to either set a large keep-alive interval (or unclean sessions) on the MQTT connection to match with the interval you are checking for messages and rely on QoS 1 or 2 (harder), or close and re-open MQTT connections and rely on retain (easier).
If you only need the MQTT messages to get through when the application is in the foreground or background, you can use something like https://github.com/ocetnik/react-native-background-timer to setInterval and wake-up to check for messages at specific intervals that have tight granularity. If you need the messages to get through even when the app has been closed, you require something like https://github.com/vikeri/react-native-background-job , which will only allow you to run code at a granularity of 15 minutes and above.
I wish you the best of luck!
Related
We have been trying to use RabbitMQ to transfer data from Project A to Project B.
We created a producer who takes the data from Project A and puts it in a queue, and that was relatively easy. Then, create a k8s pod for Project B, which listens to the appropriate queue with the ConsumerMixin of kombu.
Overall, the integration was reasonable and straightforward. But when we started to process long messages, we noticed that they were coming back into the queue repeatedly.
After research, we found out that whenever the processing of the message takes more than 20 seconds, the message showed up in the queue again, even though the processing was successful.
The source of this issue lies with the heartbeat of RabbitMQ. We set the heartbeat for 10 seconds, and the RabbitMQ checks the connection twice before it kills it. However, because the process of the callback takes more than 20 seconds, and the .ack() (acknowledge) of the message happens at the end of the callback (to ensure it was successful), the heartbeat is being blocked by the process of this message (as described here: https://github.com/celery/kombu/issues/621#issuecomment-251836611).
We have been trying to find a workaround with Threading, to process the message on a different thread and avoid the block of the heartbeat, but it didn't work. Also, it feels like we were trying to hack things and not solve the problem.
So my question here is if there is a proper workaround to handle this situation, or what alternatives do we have? RabbitMQ seemed like the right choice since we use it in standalone projects with Celery, and it is also recommended on the internet.
This is like a really basic feature an application must perform.
The app has a queue of tasks pending and is waiting for the Internet to come online for execution.
Its easy to do this in foreground by using a stream subscription. But how would one achieve this when the app is closed?
I am trying to make a chat app using XMPP protocol. The app is working fine except it doesn't show message notification when the app is in background. In Android I have used a Service for this purpose, however in Windows Phone I couldn't find anything similar to this.
I am trying Background Tasks for this, but as far as I have understood, they're made to run on prespecified trigger and I cannot add any custom trigger to it. In Android I have put my socket connection and parsing message calls in the service itself so that they can run on background too and the socket doesn't get closed even when the app is stopped.
So my question is, is there any similar way to do it in Windows Phone 8.1 (WinRT, not silverlight) or if Background Task is the only option, can you suggest a way to implement the notification functionality. I don't need the exact code, I just need a push to the right direction.
First: You cannot run a network connection in background.
Suggested way is using PushNotifications:
Either directly with a Toast Notification
Or with a PushTrigger to handle a Raw Notification, work out what to do
with it (who was it from, prepare data, etc.) and then create a ShellToast from it. Adds flexibility and improves user experience, but is quite complex.
Known downside: You have to use a server.
Only workarounds: Background-Tasks that checks for new messages about every 30 Minutes.
I need to connect an iOS Device to a computer/mac. It's necessary to take this connection alive, even if the app goes in background mode. I know that the normal life cycle of a multitasking app will cut the connection at unknown time. Now my idea was to declare the app as an VOIP-App, so that I can use the SignOfLive to send signal to the PC. Is that possible?
Please note that I'm only asking if it's possible, not if apple would like this way ;)
Sure it's possible to set any app as a VoIP app and enable keep-alives. But, Apple will reject the app and the keep-alive trigger interval has a 600 second minimum and can only run for 30-seconds.
The keep-alive is limited and is really intended for sending SIP registrations.
Why don't you describe what you are trying to accomplish and someone may be able to offer a better solution?
The voip setting will also allow the app to listen for network traffic, while in the background. Or, if you just need to be able to have a network process finish, any app can continue to run in the background for up to 10 minutes.
I am developing a client/server application with net tcp binding and I need to be notified if my connection to server goes down.
From server-side if a client disconnects, i can detect it instantly with CommunicationObject. Faulted event (with reliable session off). However, from Client side, it seems I have no way to know if server goes down. Same event doesn't fire. By the way I am setting receiveTimeout to infinite. Some people suggested a heartbeat or ping function to check if server is alive. But i think at WCF level such methodologies have big impacts. After all it's not a simple packet you send , it's the whole WCF request. What should I do ?
There seems to be a common misconception that, in order to find out on the client side whether a WCF session is still alive, one has to implement some kind of custom ping or heartbeat operation on the service. However, the WCF framework, when configured correctly, already does this for you in the background.
The trick is to set the ReliableSession.InactivityTimeout to a period that is short enough. For instance, if you set it to 30 seconds, then the ICommunicationObject.Faulted event will be raised on the client proxy after 30 (minimum) to appr. 45 (maximum) seconds after a service breakdown. The exact delay depends on the rhythm of the WCF-internal session keep-alive control timer and the specific time of the breakdown.
Of course, this can only work for reliable-session capable bindings, combined with the right session properties (ServiceContractAttribute.SessionMode, ServiceBehaviorAttribute.InstanceContextMode, OperationContractAttribute.IsInitiating, and OperationContractAttribute.IsTerminating).