Skip to main content
added 137 characters in body
Source Link
jdwolf
  • 5.3k
  • 1
  • 16
  • 29

All subscribers need to be notified of new data in a way that doesn't affect other subscribers and the server must not have to keep track of what data subscribers have received. This makes FIFO useless for this purpose. Ironically a regular file will do exactly what you want because file descriptors on regular files keep track of file changes. You can combine this with overwrite which ensures all changes are published before a new overwrite occurs meaning you are only storing one message.

touch pubsub

tail -f pubsub | while read line; do echo $line; done
tail -f pubsub | while read line; do echo $line; done

echo "message" | cat > pubsub

You will get "file truncated" on standard error which is expected behavior but if you don't want to see it add 2> /dev/null

tail is actually doing everything read and echo do but its written like that because I assume you want to incorporate it in a script.

All subscribers need to be notified of new data in a way that doesn't affect other subscribers and the server must not have to keep track of what data subscribers have received. This makes FIFO useless for this purpose. Ironically a regular file will do exactly what you want because file descriptors on regular files keep track of file changes. You can combine this with overwrite which ensures all changes are published before a new overwrite occurs meaning you are only storing one message.

touch pubsub

tail -f pubsub | while read line; do echo $line; done
tail -f pubsub | while read line; do echo $line; done

echo "message" | cat > pubsub

You will get "file truncated" on standard error which is expected behavior but if you don't want to see it add 2> /dev/null

All subscribers need to be notified of new data in a way that doesn't affect other subscribers and the server must not have to keep track of what data subscribers have received. This makes FIFO useless for this purpose. Ironically a regular file will do exactly what you want because file descriptors on regular files keep track of file changes. You can combine this with overwrite which ensures all changes are published before a new overwrite occurs meaning you are only storing one message.

touch pubsub

tail -f pubsub | while read line; do echo $line; done
tail -f pubsub | while read line; do echo $line; done

echo "message" | cat > pubsub

You will get "file truncated" on standard error which is expected behavior but if you don't want to see it add 2> /dev/null

tail is actually doing everything read and echo do but its written like that because I assume you want to incorporate it in a script.

Source Link
jdwolf
  • 5.3k
  • 1
  • 16
  • 29

All subscribers need to be notified of new data in a way that doesn't affect other subscribers and the server must not have to keep track of what data subscribers have received. This makes FIFO useless for this purpose. Ironically a regular file will do exactly what you want because file descriptors on regular files keep track of file changes. You can combine this with overwrite which ensures all changes are published before a new overwrite occurs meaning you are only storing one message.

touch pubsub

tail -f pubsub | while read line; do echo $line; done
tail -f pubsub | while read line; do echo $line; done

echo "message" | cat > pubsub

You will get "file truncated" on standard error which is expected behavior but if you don't want to see it add 2> /dev/null