title: zeromq / zmqpp : Forward metadata with message
body: <p>With zmq and zmqpp, I am looking for a way to forward meta-data along with the message it belong. The goal is to get the 'User-Id' in a worker behind a load balancer which own the secure socket.</p>
  
  <p>Here is a simple example, you can see the metadata disappear after being forwarded. I am not sure: is this metadata 'vanishment' a bug or a feature? Is there any workaround?</p>
  
  <pre><code>#include "zmqpp/zmqpp.hpp"
  #include "zmqpp/curve.hpp"
  
  int main()
  {
      zmqpp::curve::keypair client_keypair = zmqpp::curve::generate_keypair();
      zmqpp::curve::keypair server_keypair = zmqpp::curve::generate_keypair();
  
      std::cout &lt;&lt; "Client Public Key: " &lt;&lt; client_keypair.public_key &lt;&lt; std::endl;
      std::cout &lt;&lt; "Server Public Key: " &lt;&lt; server_keypair.public_key &lt;&lt; std::endl;
  
      zmqpp::context context;
  
      zmqpp::auth authenticator(context);
      authenticator.set_verbose(false);
      authenticator.configure_curve(client_keypair.public_key);
  
      zmqpp::socket curve_rep(context, zmqpp::socket_type::rep);
      curve_rep.set(zmqpp::socket_option::curve_server, true);
      curve_rep.set(zmqpp::socket_option::curve_secret_key, server_keypair.secret_key);
      curve_rep.bind("tcp://127.0.0.1:4242");
  
      zmqpp::socket curve_req(context, zmqpp::socket_type::req);
      curve_req.set(zmqpp::socket_option::curve_server_key, server_keypair.public_key);
      curve_req.set(zmqpp::socket_option::curve_public_key, client_keypair.public_key);
      curve_req.set(zmqpp::socket_option::curve_secret_key, client_keypair.secret_key);
      curve_req.connect("tcp://127.0.0.1:4242");
  
      zmqpp::socket internal_rep(context, zmqpp::socket_type::rep);
      internal_rep.bind("inproc://clear");
  
      zmqpp::socket internal_req(context, zmqpp::socket_type::req);
      internal_req.connect("inproc://clear");
  
      {
          zmqpp::message msg;
          msg &lt;&lt; "Hello";
          curve_req.send(msg);
      }
  
      {
          zmqpp::message msg;
          curve_rep.receive(msg);
  
          // read User-Id
          std::string user_id;
          std::cout &lt;&lt; "- Before forward: ";
          if (msg.get_property("User-Id", user_id))
              std::cout &lt;&lt; user_id &lt;&lt; std::endl;
          else
              std::cout &lt;&lt; "No user id" &lt;&lt; std::endl;
  
          // Forward message
          internal_req.send(msg);
      }
  
      {
          zmqpp::message msg;
          internal_rep.receive(msg);
  
          // read User-Id
          std::string user_id;
          std::cout &lt;&lt; "- After forward: ";
          if (msg.get_property("User-Id", user_id))
              std::cout &lt;&lt; user_id &lt;&lt; std::endl;
          else
              std::cout &lt;&lt; "No user id" &lt;&lt; std::endl;
  
          std::string content;
          msg &gt;&gt; content;
  
          std::cout &lt;&lt; "- Message: " &lt;&lt; content &lt;&lt; std::endl;
      }
  
      {
          zmqpp::message msg;
          msg &lt;&lt; "world !";
          internal_rep.send(msg);
      }
  
      {
          zmqpp::message msg;
          internal_req.receive(msg);
          // Forward message
          curve_rep.send(msg);
      }
  
      {
          zmqpp::message msg;
          curve_req.receive(msg);
          std::cout &lt;&lt; "- Message: " &lt;&lt; msg.get&lt;std::string&gt;(0) &lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Client Public Key: }-}3(fH/r!I/9*tJX0bN/TT]Y2Qd#{IqszYzBX.g
  Server Public Key: !@kpBlDrmW@e3jW)q6FumkKGjv@7lU?y9mD(QWd8
  auth: Starting ZAP Authentication Server
  - Before forward: }-}3(fH/r!I/9*tJX0bN/TT]Y2Qd#{IqszYzBX.g
  - After forward: No user id
  - Message: Hello
  - Message: world !
  auth: Shutdown ZAP Authentication Server
  </code></pre>