Esempio n. 1
0
int main()  {

        // Perform setup
        AmqpClient::Channel::ptr_t channel = AmqpClient::Channel::Create("localhost");

        channel->DeclareQueue(QUEUE_NAME, false, false, false, false);
        channel->BindQueue(QUEUE_NAME, EXCHANGE_NAME, ROUTING_KEY); // This needs to be changed

        AmqpClient::BasicMessage::ptr_t message = AmqpClient::BasicMessage::Create();
        string msg_body;

        do {
                cout << "What message would you like to send to your friend?\n";
                cin >> msg_body;
                message->Body(msg_body);

                channel->BasicPublish(EXCHANGE_NAME, ROUTING_KEY, message);

        } while (msg_body.compare(QUIT));

        return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	int argi = 1;
	std::string host;
	std::string base;
	std::string user;
	std::string pass;
	std::string filename;

	while (argc > argi && *argv[argi] == '-') // option
	{
		switch (*(argv[argi] + 1))
		{
			case 'h':
				++argi;
				host = argv[argi];
				break;
			case 'b':
				++argi;
				base = argv[argi];
				break;
			case 'f':
				++argi;
				filename = argv[argi];
				break;
			case 'u':
				++argi;
				user = argv[argi];
				break;
			case 'p':
				pass = argv[argi] + 2;
				break;
			default:
				std::cout << "       -h  Host" << std::endl
				<< "       -b  base.collection" << std::endl
				<< "       -f  path to save feeds" << std::endl;
				return EXIT_FAILURE;
		}
		argi++;
	}

	const char rssDir[] = "rss-files/";
	char *dir = new char[strlen(parseLastDir(__FILE__).c_str()) + strlen(rssDir) + 1];
	strcpy(dir, parseLastDir(__FILE__).c_str());
	strcat(dir, "rss-files/");
	FILE *file = fopen(filename.c_str(), "r");
	downloadFromFile(file, dir);
	delete[] dir;
	try
	{
		Mongo mongo1(host, base);
		if (!mongo1.auth(user, pass))
			return 2;
		RSS feed(mongo1);
		if (!feed.countFeeds()) //TODO логгировать каждый запуск
			return 0;
		feed.insertToDB(mongo1);
		AmqpClient::Channel::ptr_t connection = AmqpClient::Channel::Create("localhost");
		connection->DeclareQueue("hello", false, false, false, false);
		connection->BasicPublish("", "hello", AmqpClient::BasicMessage::Create("update"));
	}
	catch (mongo::DBException &e)
	{
		std::cout << "caught DBException " << e.toString() << std::endl;
		return 1;
	}

	return 0;
}