qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quynh Duong <quynhduon...@outlook.com>
Subject RE: qpid cpp pub/sub
Date Wed, 02 Jul 2014 16:40:49 GMT
Code got messed up, resending:
//Java cod starts
//using Qpid Java client 0.28 AMQP1.0 libraries
package org.apache.qpid.amqp_1_0.jms.example;
import javax.jms.*;import javax.naming.Context;import javax.naming.InitialContext;import java.util.Hashtable;

public class Spout{
    public Spout()    {    }
    @SuppressWarnings({ "rawtypes", "unchecked" })	public static void main(String[] args)
   {        try        {            Class.forName("org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
            Hashtable env = new Hashtable();            env.put("java.naming.provider.url",
"hello.properties");            env.put("java.naming.factory.initial", "org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
            Context context = new InitialContext(env);                        ConnectionFactory
connectionFactory = (ConnectionFactory) context.lookup("localhost");            Connection
connection = connectionFactory.createConnection();                       connection.start();
           
            Session producersession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
           Destination topic = producersession.createTopic("news");//if i change the address
to "news/somestuff" sub can't see, even if addresses match
            int count = 2;
            MessageProducer producer = producersession.createProducer(topic);            
                    for (int i=0; i < count; i++)            {            	Message msg
= producersession.createTextMessage("Hello news!");                producer.send(msg);   
            System.out.println("\n------------- Msg -------------");                System.out.println(msg);
               System.out.println("-------------------------------\n");            }     
      producer.close();
            connection.close();            context.close();        }        catch (Exception
exp)        {            System.out.println("Caught exception: " + exp.getMessage());    
       exp.printStackTrace();        }    }}
//Java code ends

//C++ code starts
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Message.h>
#include <qpid/messaging/Message_io.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Session.h>
#include <iostream>
using namespace qpid::messaging;using namespace qpid::types;using namespace std;
int main(){    Connection connection;    try {        string url = "localhost:5672";     
  string connectionOptions = "{protocol:amqp1.0}";        string address = "news";//if i change
the address to "news/somestuff" sub can't see, even if addresses match
        connection = Connection(url, connectionOptions);        connection.open();       
Session session = connection.createSession();        Receiver receiver = session.createReceiver(address);
       Duration timeout = 300 * Duration::SECOND;        int count = 5;        Message message;
       int i = 0;
        while (receiver.fetch(message, timeout)) {            std::cout << message <<
std::endl;            session.acknowledge();            if (count && (++i == count))
               break;        }        receiver.close();        session.close();        connection.close();
       return 0;    } catch(const std::exception& error) {        std::cout << "Error:
" << error.what() << std::endl;        connection.close();    }    return 1;}//C++
code ends 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message