linux进程号61616,[转载]摘录一个LINUX下的C程序,调用activemq的C/C++

一、源码如下:【存成amq_cli.cpp】

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

//#include

//#include

#include

#include

#include

#include

#include

using namespace activemq::core;

using namespace decaf::util::concurrent;

using namespace decaf::util;

using namespace decaf::lang;

using namespace cms;

using namespace std;

string gettext()

{

string

text="hello ttsky!!";

return text;

}

void sentmessage()

{

activemq::library::ActiveMQCPP::initializeLibrary();

std::auto_ptr<:connectionfactory>

connectionFactory(

cms::ConnectionFactory::createCMSConnectionFactory(

"tcp://192.168.1.152:61616" ) );

//建立连接工厂

while(true)

{

Connection* connection =

connectionFactory->createConnection();

connection->start();//创建连接

printf("connect a messagern");

Session* session =

connection->createSession(cms::Session::AUTO_ACKNOWLEDGE

);

//创建线程

string text = gettext();

TextMessage* message = session->createTextMessage(

text );//创建消息

Destination* destination;

destination=NULL;

destination = session->createQueue( "ttsky"

);//创建队列

MessageProducer*

myproducer=session->createProducer(destination

);

myproducer->setDeliveryMode(

DeliveryMode::NON_PERSISTENT );//消息的持久性

// long long startTime = Date::getCurrentTimeMilliseconds();

myproducer->send(message );//发送消息

printf("send a messagern");

session->close();

connection->close();

// long long

endTime = Date::getCurrentTimeMilliseconds();

// double

totalTime = (endTime - startTime) / 1000.0;

// std::cout

<< "Time to completion = "

<< totalTime

<< " seconds."

<< std::endl;

sleep(5);

}

activemq::library::ActiveMQCPP::shutdownLibrary();

}

int main(int argc AMQCPP_UNUSED, char* argv[] AMQCPP_UNUSED)

{

sentmessage();

}

二、编译

[root@localhost

Desktop]# g++ -o amq_cli amq_cli.cpp -lactivemq-cpp

当然,编译之前还需要安装下面几个库:

1、apr-1.4.2.tar.gz

2、apr-util-1.3.10.tar.gz

3、activemq-cpp-library-3.2.4-src.tar.gz

其中,以上第2个工具安装的时候,要用 ./configure --with-apr=/usr/local/apr,指明第1个工具apr安装的路径,才能产生makefile文件。

如果编译时找不到头文件, 这样搞一下:

[root@m176com activemq-cpp-3.2.4]# cp ./cms

/usr/local/include/ -R

[root@m176com activemq-cpp-3.2.4]# cp ./decaf/

/usr/local/include/ -R [root@m176com activemq-cpp-3.2.4]# cp ./activemq/

/usr/local/include/ -R

三、运行:

运行时找不到动态库。

[root@localhost Desktop]# ./amq_cli

./amq_cli: error while loading shared libraries:

libactivemq-cpp.so.12: cannot open shared object file: No such file

or directory

在/etc/ld.so.conf中加入 libactivemq-cpp.so.12 所在的目录

[root@localhost

Desktop]# cat

/etc/ld.so.conf

/usr/local/lib[root@localhost Desktop]# ldconfig

再运行,就OK了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值