How do I use kombu with pika async? - asynchronous

I'm trying to use kombu to write a server that will process two messages at the same time. My transport is rabbitmq.
I believe the answer is to use kombu with pika-async. However, there doesn't seem to be any documentation on how to do this.
Help?

I figured it out.
You should use gevent or eventlet to make all the calls async.

Related

NamedPipeClientStream - Notifications if server has disconnected

I have a question and I couldn't find any answer here.
I am using the NamedPipeClientStream/NamedPipeServerStream classes for bidirectional IPC communication in a .NET 5.0/.NET Framework 4.8 environment and it works fine, however I need to have a way of letting the client (immediately) know if the server is not running anymore and I am not sure what is the best way to achieve this.
Of course I can try on the client side to call Connect with a timeout every 3 seconds for example and if I get a TimeoutException, then it means the server is not available, however as far I as have read, doing this (for example with a timer and/or a background thread) is not very efficient. Are there better ways to do this (and still use named pipes)? Can someone point me in another (better) direction?
I had it solved before with WCF, however as .NET Core doesn't support it, it is not a solution anymore.
Thank you very much.
BR,
M.
You could do a twofold approach where if a server shuts down nicely you send a 'i am shutting down' message to the client. And also have the server send small heartbeat messages once per second to clients. This way clients can check if the last heartbeat is stale or the server has shutdown whenever they need.
Looking for a WCF replacement myself and came across your post ;-)

Free up workers for processing while waiting for long DB queries (uWSGI)?

I am maintaining API server for my company which runs a python flask app in uwsgi on top of nginx.
...
#app.route('/getquick', methods=["GET"])
def GET_GET_IP_DATA():
sp_final = "CALL sp_quick()"
cursor.execute(sp_final)
#app.route('/get_massive_log', methods=["POST"])
def get_massive_log():
sp_final = "CALL sp_slow()"
cursor.execute(sp_final)
...
While the first request /getquick gets processed very quickly, /get_massive_log can take up to five seconds due to a rather long and complex mySQL query. The server can handle few of these queries but starts creating broken pipe errors when called to much.
The problem is, the other /getquick requests get blocked by these long I/O requests.
My manager suggested that I use gevent to somehow free up the server to process the other requests while waiting for the mySQL queries, but I am not sure if I am looking in the correct direction.
I am using pymysql to run queries, which google seems to suggest to work with gevent on top of uwsgi, but I have not been able to produce better results with it.
I have googled for days now, and while I am trying to understand threads, concurrency, asynchronous requests, I don't know where to start digging to find a solution. Is it even possible? Any suggestions or even pointers to where to research would be greatly appreciated.
EDIT : Perhaps my questions wasn't too clear, so I'll try to restate it:
What's the best way to free up workers for processing other requests while waiting for long database queries with uwsgi?
You need to learn about Uwsgi offloading
Offloading is a way to optimize tiny tasks, delegating them to one or
more threads.
These threads run such tasks in a non-blocking/evented way allowing
for a huge amount of concurrency.
You can read about offloading subsystem in the docs

Terminating a voice call via AT Command

Im working on a hobby project involving an Arduino and TC35 GSM Module, all is going well really but I am wondering is there an AT Command to terminate a voice call (ATD+phone number;) as I cannot seem to find one in any of the literature I've searched through.
Thanks,
Dave
While the "classic" command ATH (there is no need to give a numerical argument to ATH) is applicable for disconnecting calls, notice that it might be configured to do nothing by AT+CVHU=1 (ignore DTR pin and ATH) for other phones (TC35 seems to not support AT+CVHU).
There is the AT+CHUP command that always will hang up the current call, independently of ATH behaviour configuration.
The 27.007 standard also defines an AT+CHCCS (Hangup of current calls) command that can be used to disconnect calls. Also AT+CHLD might be used to disconnect calls.
I think the answer to your question is
ATH0 from memory
The command you are looking for is ATH0 (Also dredged from my memory) but then confirmed with the Official Documentation
ATH command ends call ONLY when call was answered.
AT+CHUP command ends call whenever answered or not

How can a LuaSocket server handle several requests simultaneously?

The problem is the inability of my Lua server to accept multiple request simultaneously.
I attempted to make each client message be processed in its on coroutine, but this seems to have failed.
while true do
local client = server:accept()
coroutine.resume(coroutine.create( function()
GiveMessage( client )
end ) )
end
This code seems to not actually accept more than one client message at the same time. What is wrong with this method? Thank you for helping.
You will not be able to create true simultaneous handling with coroutines only — coroutines are for cooperative multitasking. Only one coroutine is executed at the same time.
The code that you've wrote is no different from calling GiveMessage() in a loop directly. You need to write a coroutine dispatcher and find a sensible reason to yield from GiveMessage() for that approach to work.
There are least three solutions, depending on the specifics of your task:
Spawn several forks of your server, handle operations in coroutines in each fork. Control coroutines either with Copas or with lua-ev or with home-grown dispatcher, nothing wrong with that. I recommend this way.
Use Lua states instead of coroutines, keep a pool of states, pool of worker OS threads and a queue of tasks. Execute each task in a free Lua state with a free worker thread. Requires some low-level coding and is messier.
Look for existing more specialized solutions — there are several, but to advice on that I need to know better what kind of server you're writing.
Whatever you choose, avoid using single Lua state from several threads at the same time. (It is possible, with the right amount of coding, but a bad idea.)
AFAIK coroutines don't play nice with luaSocket out-of-the-box. But there is Copas you can use.

How do I ping from Flex - AIR?

I'm bored cause my development server is down and I'm running the command prompt to ping the server indefinitely so that I'll see when they stop timing out and know that I can work again. In the meantime I wanted to make an Air app that will do this for me, so I can have it chirp or alarm or do something when it starts to be able to connect to the server.
So I need to start with having AIR do the ping, does anyone know how to do this? I can't find any help on it. I can't use the HTTPService because whatever it is that is broken (think it's the VPN), our dev web site is still up.
Thanks
Otherwise you can use the NativeProcess class of the AIR 2.0 beta, and use the ping command of your operating system.
You can find informations on how to use it here.
According to the docs, SocketMonitor, descending from ServiceMonitor will check basic availability, but not a true ping. If you want to truly "ping" the server, you would need to use a socket an implement the protocol, This link to the Wikipedia article might help.
The AIR SDK offers some classes (URLMonitor, SocketMonitor) to handle this:
http://livedocs.adobe.com/flex/3/html/help.html?content=network_connectivity_1.html

Resources