Search in sources :

Example 1 with VCMessagingServiceActiveMQ

use of cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ in project vcell by virtualcell.

the class TestBlobRpcMessages method main.

public static void main(String[] args) throws Exception {
    try {
        PropertyLoader.loadProperties();
        // System.getProperties().setProperty(PropertyLoader.jmsURL,"tcp://nrcamdev5.cam.uchc.edu:61616");
        VCMessagingService messagingService = new VCMessagingServiceActiveMQ();
        messagingService.setDelegate(new SimpleMessagingDelegate());
        // reading message and computing sum
        // create N comsumers
        MyRpcServer myRpcServer = new MyRpcServer();
        for (int i = 0; i < NUM_COMSUMERS; i++) {
            VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellTestQueue.JimQueue);
            VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, rpcMessageHandler, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== RPC Consumer Thread " + i, 1);
            messagingService.addMessageConsumer(rpcConsumer);
        }
        // creating one messageProducer session
        ArrayList<VCMessageSession> sessions = new ArrayList<VCMessageSession>();
        for (int i = 0; i < NUM_PRODUCERS; i++) {
            sessions.add(messagingService.createProducerSession());
        }
        for (int i = 0; i < NUM_MESSAGES; i++) {
            for (int s = 0; s < NUM_PRODUCERS; s++) {
                VCMessageSession session = sessions.get(s);
                try {
                    // 
                    // create simple RPC request for service "Testing_Service"
                    // 
                    User user = new User("schaff", new KeyValue("17"));
                    byte[] array1 = new byte[20000000];
                    byte[] array2 = new byte[20000000];
                    VCRpcRequest rpcRequest = new VCRpcRequest(user, RpcServiceType.TESTING_SERVICE, "concat", new Object[] { array1, array2 });
                    // 
                    // send request and block for response (or timeout).
                    // RPC invocations don't need commits.
                    // 
                    Object returnValue = session.sendRpcMessage(VCellTestQueue.JimQueue, rpcRequest, true, 20000, null, null, null);
                    // 
                    if (returnValue instanceof byte[]) {
                        System.out.println("concat(byte[" + array1.length + "], byte[" + array2.length + "]) ===> byte[" + (((byte[]) returnValue).length) + "]");
                    } else {
                        System.out.println("unexpected return value of " + returnValue);
                    }
                } catch (VCMessagingInvocationTargetException e) {
                    e.printStackTrace(System.out);
                    System.out.println("the rpc service threw an exception");
                    e.getTargetException().printStackTrace(System.out);
                }
            }
        }
        System.out.println("main program calling closeAll()");
        messagingService.close();
        System.out.println("main program exiting");
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : SimpleMessagingDelegate(cbit.vcell.message.SimpleMessagingDelegate) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCMessageSession(cbit.vcell.message.VCMessageSession) ArrayList(java.util.ArrayList) VCMessagingService(cbit.vcell.message.VCMessagingService) VCRpcRequest(cbit.vcell.message.VCRpcRequest) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) VCMessagingServiceActiveMQ(cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler)

Example 2 with VCMessagingServiceActiveMQ

use of cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ in project vcell by virtualcell.

the class TestBlobMessages method setUp.

@Before
public void setUp() throws Exception {
    System.getProperties().put("vcell.mongodb.host", "localhost");
    System.getProperties().put("vcell.mongodb.port", "27017");
    System.getProperties().put("vcell.mongodb.database", "test");
    mongoDbDriver = VCMongoDbDriver.getInstance();
    System.getProperties().put("vcell.jms.url", "failover:(tcp://localhost:61616)");
    System.getProperties().put("vcell.jms.user", "clientUser");
    System.getProperties().put("vcell.jms.pswdfile", "~/vcellkeys/jmspswd.txt");
    System.getProperties().put("vcell.jms.blobMessageUseMongo", "true");
    System.getProperties().put("vcell.jms.blobMessageMinSize", "100000");
    messagingService = new VCMessagingServiceActiveMQ();
    messagingService.setDelegate(new SimpleMessagingDelegate());
}
Also used : SimpleMessagingDelegate(cbit.vcell.message.SimpleMessagingDelegate) VCMessagingServiceActiveMQ(cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ) Before(org.junit.Before)

Aggregations

SimpleMessagingDelegate (cbit.vcell.message.SimpleMessagingDelegate)2 VCMessagingServiceActiveMQ (cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ)2 VCMessageSession (cbit.vcell.message.VCMessageSession)1 VCMessagingInvocationTargetException (cbit.vcell.message.VCMessagingInvocationTargetException)1 VCMessagingService (cbit.vcell.message.VCMessagingService)1 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)1 VCRpcMessageHandler (cbit.vcell.message.VCRpcMessageHandler)1 VCRpcRequest (cbit.vcell.message.VCRpcRequest)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 KeyValue (org.vcell.util.document.KeyValue)1 User (org.vcell.util.document.User)1