Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Java interact with System V linux message queues?

I need to pass information from a shell script (called from a linux based app) to a java application.

Named pipes are a pain because I can't start/stop either service without considering complex repercussions to the read/write ends of the pipes.

Sockets are tough because if the listening process is restarted there's no queuing mechanism, and simple implementations require new sockets be constantly created (else the shell script will get very complex with check-and-restart-socket, and queuing code).

I was recently reading about these System V/POSIX linux message queues. I'm running Fedora 12, and wonder if there's a good way to configure these message queues and interact with them from Java.

like image 688
David Parks Avatar asked Jun 20 '11 05:06

David Parks


1 Answers

You can't use them directly, you'd have to do some JNI wizardry to interface them together.

What problems are you having with Pipes? Java sees those as just generic files. I haven't used them extensively, but I didn't have any real problems with Pipes. The only detail there was the pipe reader needs to continually reopen the pipe if the producers can't keep up.

But if either side fails, the other side just blocks waiting for the other to recover.

You just have to be careful with buffer reads from the pipe. If you read from the pipe in to a buffer, and then fail, that data is lost.

like image 197
Will Hartung Avatar answered Sep 30 '22 03:09

Will Hartung