adding possibility to resend failed messages
separating encode and send functionality
producer detects far end closing connection
fixes in tests