int main()
{
    char* szBroker = getenv("AMQP_BROKER");
    Channel::ptr_t channel;
    if (szBroker != NULL)
        channel = Channel::Create(szBroker);
    else
        channel = Channel::Create();

	channel->DeclareQueue("alanqueue");
	channel->BindQueue("alanqueue", "amq.direct", "alankey");

	BasicMessage::ptr_t msg_in = BasicMessage::Create();

	msg_in->Body("This is a small message.");

	channel->BasicPublish("amq.direct", "alankey", msg_in);

	channel->BasicConsume("alanqueue", "consumertag");

	BasicMessage::ptr_t msg_out = channel->BasicConsumeMessage("consumertag")->Message();

	std::cout << "Message text: " << msg_out->Body() << std::endl;

}
Пример #2
0
void receive(int id)
{
    Channel::ptr_t channel;
    channel = Channel::Create("192.168.8.102");
    std::string e_name = "tieto-chatroom";

    //preparation
    channel->DeclareExchange(e_name, Channel::EXCHANGE_TYPE_FANOUT);
    std::string q_name = channel->DeclareQueue("", false, true, false);
    channel->BindQueue(q_name, e_name, "chat");

    channel->BasicConsume(q_name, "");
    Envelope::ptr_t env;
    while (true)
    {
        if (channel->BasicConsumeMessage(env, -1))
        {
            std::cout << "Received by " << id << ": " <<
                         env->Message()->Body() << " [" <<
                         env->Exchange() << "]" << std::endl;

        } else {
            std::cout << "queue empty" << std::endl;
            break;
        }
    }
}
Пример #3
0
TEST(test_get, get_big)
{
  // Smallest frame size allowed by AMQP
  Channel::ptr_t channel = Channel::Create(connected_test::GetBrokerHost(), 5672, "guest", "guest", "/", 4096);
  // Create a message with a body larger than a single frame
  BasicMessage::ptr_t message = BasicMessage::Create(std::string(4099, 'a'));
  std::string queue = channel->DeclareQueue("");

  channel->BasicPublish("", queue, message);
  Envelope::ptr_t new_message;
  EXPECT_TRUE(channel->BasicGet(new_message, queue));
  EXPECT_EQ(message->Body(), new_message->Message()->Body());
}
Пример #4
0
int main()
{
  const std::string EXCHANGE_NAME = "SimpleAmqpClientEnvelopeTest";
  const std::string ROUTING_KEY = "SACRoutingKey";
  const std::string CONSUMER_TAG = "SACConsumerTag";

  try
  {
    Channel::ptr_t channel = Channel::Create();

    channel->DeclareExchange(EXCHANGE_NAME, Channel::EXCHANGE_TYPE_FANOUT);
    std::string queue = channel->DeclareQueue("");
    channel->BindQueue(queue, EXCHANGE_NAME, ROUTING_KEY);

    channel->BasicPublish(EXCHANGE_NAME, ROUTING_KEY, BasicMessage::Create("MessageBody"));
    channel->BasicPublish(EXCHANGE_NAME, ROUTING_KEY, BasicMessage::Create("MessageBody2"));
    channel->BasicPublish(EXCHANGE_NAME, ROUTING_KEY, BasicMessage::Create("MessageBody3"));

    channel->BasicConsume(queue, CONSUMER_TAG);

    Envelope::ptr_t env;
    for (int i = 0; i < 3; ++i)
    {
      if (channel->BasicConsumeMessage(env, 0)) 
      {
        std::cout << "Envelope received: \n" 
          << " Exchange: " << env->Exchange()
          << "\n Routing key: " << env->RoutingKey() 
          << "\n Consumer tag: " << env->ConsumerTag()
          << "\n Delivery tag: " << env->DeliveryTag()
          << "\n Redelivered: " << env->Redelivered() 
          << "\n Body: " << env->Message()->Body() << std::endl;
      }
      else
      {
        std::cout << "Basic Consume failed.\n";
      }
    }
  }
  catch (AmqpResponseServerException& e)
  {
    std::cout << "Failure: " << e.what();
  }
  return 0;
}