Home Help Center

Problem with IceStorm

minifatminifat Member Yan YaqinOrganization: CEPRIProject: data interface ✭✭
Folks, i'm practising IceStorm , but it is not successful.
Code is like that
//pub.cpp
#include <Ice/Ice.h>
#include <IceStorm/IceStorm.h>
#include <Monitor.h>
#include <iostream>
using namespace std;
Measurement getMeasurement()
{
static float id = 0.0;
Measurement m;
m.tower = "haha";
m.windSpeed = id;
m.windDirection = 10;
m.temperature = 1.0;
id += 10 ;
return m;
}
int main( int argc , char *argv[] )
{
Ice::CommunicatorPtr ic;
ic = Ice::initialize( argc, argv );
Ice::ObjectPrx obj = ic->stringToProxy(
"IceStorm/TopicManager:default -p 10000");
IceStorm::TopicManagerPrx topicManager =
IceStorm::TopicManagerPrx::checkedCast( obj );
IceStorm::TopicPrx topic;
try{
topic = topicManager->retrieve("Weather");
}
catch( const IceStorm::NoSuchTopic& ){
topic = topicManager->create("Weather");
}
Ice::ObjectPrx pub = topic->getPublisher();
if( !pub->ice_isDatagram())
pub = pub->ice_oneway();
MonitorPrx monitor = MonitorPrx::uncheckedCast( pub );
while( true ){
Measurement m = getMeasurement();
monitor->report( m );
}
}
//sub.cpp
#include <Ice/Ice.h>
#include <IceStorm/IceStorm.h>
#include <Monitor.h>
#include <iostream>
using namespace std;
class MonitorI: virtual public Monitor{
public:
virtual void report( const Measurement &m,
const Ice::Current& ){
cout<<"Measurement report:"<<endl
<<"Tower: "<<m.tower<<endl
<<"W spd:"<<m.windSpeed<<endl;

}

};
int main( int argc , char *argv[] )
{
Ice::CommunicatorPtr ic;
ic = Ice::initialize( argc, argv );

Ice::ObjectPrx obj = ic->stringToProxy(
"IceStorm/TopicManager:default -p 10000");
IceStorm::TopicManagerPrx topicManager =
IceStorm::TopicManagerPrx::checkedCast( obj );

Ice::ObjectAdapterPtr adapter
= ic->createObjectAdapter("MonitorAdapter");
MonitorPtr monitor = new MonitorI;
Ice::ObjectPrx proxy = adapter->addWithUUID( monitor );

IceStorm::TopicPrx topic;

try{
topic = topicManager->retrieve("Weather");
IceStorm::QoS qos;
topic->subscribe( qos, proxy );

}
catch( const IceStorm::NoSuchTopic& ){
cerr<<"NoSuchTopic"<<endl;
}
adapter->activate();
ic->waitForShutdown();
topic->unsubscribe( proxy );
}
config and config_service is copy from demo/IceStorm/clock

cmd i type is like:

icebox --Ice.Config=config_service
icestormadmin --Ice.Config=config
sub
pub

both sub and pub are suspended, and icebox output like this:

[[email protected] msg]# icebox --Ice.Config=config_service
[ icebox-IceStorm: TopicManager: loading topic "Weather" from database ]
[ icebox-IceStorm: Topic: Subscribe: 8491AEB5-BBB4-4BFB-97A2-1206EC2D3389 ]
[ icebox-IceStorm: Subscriber: 8491AEB5-BBB4-4BFB-97A2-1206EC2D3389: publish failed: Reference.cpp:712: Ice::NoEndpointException:
no suitable endpoint available for proxy `8491AEB5-BBB4-4BFB-97A2-1206EC2D3389 -o' ]
~

Comments

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    The Ice::NoEndpointException indicates that your subscriber object proxy doesn't have any endpoints. In sub.cpp, you create the object adapter with:
     Ice::ObjectAdapterPtr adapter = ic->createObjectAdapter("MonitorAdapter");
    

    So you need to start your subscriber with the option "--MonitorAdapter.Endpoints=tcp" to tell the object adapter to listen on the "tcp" endpoint. Proxies created through this object adapter will in turn include this "tcp" endpoint.

    If you don't want to pass this endpoint as a configuration parameter you can also use:
     Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints("MonitorAdapter", "tcp");
    

    Hope this helps!

    Benoit.
  • minifatminifat Member Yan YaqinOrganization: CEPRIProject: data interface ✭✭
    It's work:)
    ThanksI
Sign In or Register to comment.