PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label messaging. Show all posts
Showing posts with label messaging. Show all posts

Tuesday, September 20, 2022

[FIXED] What is an elegant way of halting consumption of messages gracefully in the C# client for RabbitMQ?

 September 20, 2022     amqp, c#, consumer, messaging, rabbitmq     No comments   

Issue

I am setting up a standard standalone thread listening to RabbitMQ in C#. Suppose the method for listening in the thread looks like this:

public void Listen()
{
    using (var channel = connection.CreateModel())
    {
        var consumer = SetupQueues(channel);
        while (true)
        {
            var ea = consumer.Queue.Dequeue();    // blocking call
            handler.HandleMessage(channel, ea);
        }
    }
}

What is an elegant way of halting consumption of messages gracefully in the C# client for RabbitMQ? Keep in mind I have found nothing of use in the RabbitMQ examples/docs or these SO questions:

  • How to stop consuming message from selective queue - RabbitMQ
  • How to pause and resume consumption gracefully in rabbitmq, pika python
  • What is the best way to safely end a java application with running RabbitMQ consumers

The issue here is consumer.Queue.Dequeue() is a blocking call. I have tried these options:

  • Calling channel.BasicCancel(string tag). This causes a System.IO.EndOfStreamException in the blocking call. I do not want to use this exception as part of the control flow for obvious reasons.

  • Calling consumer.Queue.Dequeue(int millisecondsTimeout, out T result) and checking a flag in between loop iterations. This can work but seems hacky.

I want to let the thread exit gracefully and clean up any unmanaged resources I might have, so no thread aborting, etc.

Any help is appreciated. Thanks


Solution

The DeQueue with the timeout & flag is the way to do it. It's a very common pattern, and is why many blocking calls are provided with timeout-enabled versions.

Alternately, throwing a (known) exception isn't necessarily a bad thing for control flow. Gracefully shutting down could mean actually trapping the exception, commenting "this is thrown when requesting the channel shuts down", and then returning cleanly. This is how part of TPL works with the CancellationToken.



Answered By - Bryan Boettcher
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, July 11, 2022

[FIXED] How Can We Read Incoming SMS by using Application in iOS

 July 11, 2022     ios, iphone, message, messaging, objective-c     No comments   

Issue

In my application I am able to send an SMS programatically to a particular mobile number when the user clicks submit button. Then there is a response message from that mobile number now I want to read that message and populate that SMS text in to my application.

I searched for this and found that this is not possible in iOS. My question is there any possibility accessing inbox SMS with user permissions?


Solution

Simply two words from Apple:

Not Possible

Detailed:

An iOS app can only access the data for which Apple supplies a documented public API. iOS can not access outside of the sandbox until Apple provides a public API for it. So intercepting/reading an incoming SMS not possible. And no idea when the iOS device is jailbroken.



Answered By - Buntylm
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing