Package com.netflix.astyanax.recipes.queue

Examples of com.netflix.astyanax.recipes.queue.MessageQueueDispatcher


                }
            }
        }, 1, 1, TimeUnit.SECONDS);

        // Consumer
        MessageQueueDispatcher dispatcher = new MessageQueueDispatcher.Builder()
                .withBatchSize(500)
                .withCallback(new Function<MessageContext, Boolean>() {
            @Override
            public Boolean apply(MessageContext message) {
                String data = (String) message.getMessage().getParameters().get("data");
                counter.incrementAndGet();
                // Return true to 'ack' the message
                // Return false to not 'ack' which will result in the message timing out
                // Throw any exception to put the message into a poison queue
                return true;
            }
        })
                .withMessageQueue(scheduler)
                .withConsumerCount(5)
                .withThreadCount(1 + 10)
                .build();

        dispatcher.start();

        executor.awaitTermination(1000, TimeUnit.SECONDS);
    }
View Full Code Here


        if(slm!=null) {
            l = slm.acquireLock(shard);
        }

        // Consumer
        MessageQueueDispatcher dispatcher = new MessageQueueDispatcher.Builder()
                .withBatchSize(25)
                .withCallback(new Function<MessageContext, Boolean>() {
                                    @Override
                                    public Boolean apply(MessageContext message) {
                                        count.incrementAndGet();
                                        return true;
                                    }
                                })
                .withMessageQueue(scheduler)
                .withConsumerCount(10)
                .withProcessorThreadCount(10)
                .withAckInterval(20, TimeUnit.MILLISECONDS)
                .withPollingInterval(15, TimeUnit.MILLISECONDS)
                .build();

        // Start the consumer
        dispatcher.start();

        // Release the lock
        if(slm!=null) {
            // Wait
            Thread.sleep(1000);
            slm.releaseLock(l);
        }

        // Wait another 10 seconds and then stop the dispatcher
        Thread.sleep(1000);
        dispatcher.stop();

        assertEquals(queuedCount, count.intValue());
        // Check the busy lock count
        if(slm!=null) {
            System.out.println("Lock attempts " + slm.getLockAttempts());
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.recipes.queue.MessageQueueDispatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.