本文整理汇总了C++中Sender::close方法的典型用法代码示例。如果您正苦于以下问题:C++ Sender::close方法的具体用法?C++ Sender::close怎么用?C++ Sender::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sender
的用法示例。
在下文中一共展示了Sender::close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: safe_sender
int
Purger_Thread::svc (void)
{
for (; !this->reactor_.reactor_event_loop_done ();)
{
// Get a connection from the cache.
Sender *sender =
this->connection_cache_.acquire_connection ();
// If no connection is available in the cache, sleep for a while.
if (sender == 0)
ACE_OS::sleep (ACE_Time_Value (0, 10 * 1000));
else
{
// The reference count on the sender was increased by the
// cache before it was returned to us.
ACE_Event_Handler_var safe_sender (sender);
// Actively close the connection.
ACE_DEBUG ((LM_DEBUG,
"Purger thread calling Sender::close() for handle %d\n",
sender->handle_));
sender->close ();
}
}
return 0;
}
示例2: main
int main(int argc, char** argv) {
const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672";
std::string connectionOptions = argc > 2 ? argv[2] : "";
Connection connection(url, connectionOptions);
try {
connection.open();
Session session = connection.createSession();
Receiver receiver = session.createReceiver("service_queue; {create: always}");
while (true) {
Message request = receiver.fetch();
const Address& address = request.getReplyTo();
if (address) {
Sender sender = session.createSender(address);
Message response;
qpid::types::Variant requestObj = request.getContentObject();
if (requestObj.getType() == qpid::types::VAR_STRING) {
// Received a string.
// Server returns request string in upper case with same encoding.
std::string s = requestObj;
std::transform(s.begin(), s.end(), s.begin(), toupper);
qpid::types::Variant responseObj(s);
responseObj.setEncoding( requestObj.getEncoding() );
response.setContentObject( responseObj );
} else {
// Received something other than a string.
// Server echos received object as a utf8 string.
qpid::types::Variant responseObj( requestObj.asString() );
responseObj.setEncoding( "utf8" );
response.setContentObject( requestObj );
}
sender.send(response);
std::cout << "Processed request: "
<< request.getContentObject()
<< " -> "
<< response.getContentObject() << std::endl;
session.acknowledge();
sender.close();
} else {
std::cerr << "Error: no reply address specified for request: " << request.getContent() << std::endl;
session.reject(request);
}
}
connection.close();
return 0;
} catch(const std::exception& error) {
std::cout << error.what() << std::endl;
connection.close();
}
return 1;
}
示例3: ACE_DEBUG
int
Invocation_Thread::svc (void)
{
int connection_counter = 0;
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("(%t) Invocation_Thread::svc commencing\n")));
disable_signal (SIGPIPE, SIGPIPE);
for (int message_counter = 1;; ++message_counter)
{
// Get a connection from the cache.
Sender *sender =
this->connection_cache_.acquire_connection ();
// If no connection is available in the cache, create a new one.
if (sender == 0)
{
if (connection_counter < number_of_connections)
{
sender = this->create_connection ();
// This lets the Close_Socket_Thread know that the new
// connection has been created.
int result =
this->new_connection_event_.signal ();
ACE_TEST_ASSERT (result == 0);
ACE_UNUSED_ARG (result);
++connection_counter;
message_counter = 1;
}
else
// Stop the thread, if the maximum number of connections
// for the test has been reached.
break;
}
// The reference count on the sender was increased by the cache
// before it was returned to us.
ACE_Event_Handler_var safe_sender (sender);
// If the test does not require making invocations, immediately
// release the connection.
if (!this->make_invocations_)
{
this->connection_cache_.release_connection (sender);
// Sleep for a short while
ACE_OS::sleep (ACE_Time_Value (0, 10 * 1000));
}
else
{
// Make invocation.
ssize_t result =
sender->send_message ();
// If successful, release connection.
if (result == message_size)
{
if (debug)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) Message %d:%d delivered on handle %d\n"),
connection_counter,
message_counter,
sender->handle_));
this->connection_cache_.release_connection (sender);
}
else
{
// If failure in making invocation, close the sender.
if (debug)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) /*** Problem in delivering message ")
ACE_TEXT ("%d:%d on handle %d: shutting down ")
ACE_TEXT ("invocation thread ***/\n"),
connection_counter,
message_counter,
sender->handle_));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) Invocation thread calling ")
ACE_TEXT ("Sender::close() for handle %d\n"),
sender->handle_));
sender->close ();
}
}
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("(%t) Invocation_Thread::svc calling end_reactor_event_loop\n")));
// Close the Reactor event loop.
this->reactor_.end_reactor_event_loop ();
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("(%t) Invocation_Thread::svc terminating\n")));
return 0;
}
示例4: run
void RequestResponse::run()
{
const char *options[] = {"", "--log-enable", "trace+", "--log-to-stdout", "on", "--log-time", "on", "--log-level", "on"};
Logger::configure(9, options);
std::string url = "amqp:ssl:" + _options.getHost() + ":" + std::to_string(_options.getPort());
Connection connection(url, "{ protocol: amqp1.0 }");
connection.setOption("sasl_mechanisms", "EXTERNAL");
connection.setOption("heartbeat", "30");
Address reply(_replyAddress);
Address request(_requestAddress);
Address response(_responseAddress);
Duration timeout = Duration::SECOND * _options.getTimeout();
try
{
connection.open();
Session session = connection.createSession();
std::cout << "-I- Connection opened, session created" << std::endl;
Sender sender = session.createSender(request);
sender.setCapacity(_capacity);
std::cout << "-I- Sender created " << sender.getName() << std::endl;
Receiver receiver = session.createReceiver(response);
receiver.setCapacity(_capacity);
std::cout << "-I- Receiver created " << receiver.getName() << std::endl;
Message requestMsg("<FIXML>...</FIXML>");
requestMsg.setDurable(false);
requestMsg.setReplyTo(reply);
sender.send(requestMsg, true);
std::cout << "-I- Request message sent" << std::endl;
try
{
Message responseMsg = receiver.fetch(timeout);
std::cout << "-I- Received message with content: " << responseMsg.getContent() << std::endl;
session.acknowledge(true);
_messageCounter++;
}
catch (NoMessageAvailable noMessage)
{
std::cout << "-I- No message received for " << timeout.getMilliseconds()/1000 << " seconds" << std::endl;
}
session.sync(true);
sender.close();
receiver.close();
session.close();
connection.close();
}
catch (const std::exception &error)
{
connection.close();
std::cerr << "-E- Caught exception: " << error.what() << std::endl;
throw error;
}
}