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;

}
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;
}
TEST(test_publish, publish_large_message)
{
    // 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'));

    channel->BasicPublish("", "test_publish_rk", message);
}
Exemple #4
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());
}