code for spawning worker threads that consume and produce messages