Search in sources :

Example 1 with InMemoryStore

use of org.apache.synapse.message.store.impl.memory.InMemoryStore in project wso2-synapse by wso2.

the class InMemoryMessageStoreTest method testOrderedDelivery2.

public void testOrderedDelivery2() throws Exception {
    System.out.println("Testing InMemoryStore Guaranteed Delivery...");
    MessageStore store = new InMemoryStore();
    store.getProducer().storeMessage(createMessageContext("FOO"));
    MessageConsumer consumer = store.getConsumer();
    MessageContext msg = consumer.receive();
    assertEquals("FOO", msg.getMessageID());
    store.getProducer().storeMessage(createMessageContext("BAR"));
    msg = consumer.receive();
    assertEquals("FOO", msg.getMessageID());
    consumer.ack();
    msg = consumer.receive();
    assertEquals("BAR", msg.getMessageID());
}
Also used : MessageConsumer(org.apache.synapse.message.MessageConsumer) InMemoryStore(org.apache.synapse.message.store.impl.memory.InMemoryStore) MessageContext(org.apache.synapse.MessageContext)

Example 2 with InMemoryStore

use of org.apache.synapse.message.store.impl.memory.InMemoryStore in project wso2-synapse by wso2.

the class InMemoryMessageStoreTest method testBasics.

public void testBasics() throws Exception {
    System.out.println("Testing Basic InMemoryStore operations...");
    MessageStore store = new InMemoryStore();
    populateStore(store, 10);
    // test size()
    assertEquals(10, store.size());
    // test get(index)
    for (int i = 0; i < 10; i++) {
        assertEquals("ID" + i, store.get(i).getMessageID());
    }
    // test get(messageId)
    for (int i = 0; i < 10; i++) {
        assertEquals("ID" + i, store.get("ID" + i).getMessageID());
    }
    // test getAll()
    List<MessageContext> list = store.getAll();
    assertEquals(10, list.size());
    for (int i = 0; i < 10; i++) {
        assertEquals("ID" + i, list.get(i).getMessageID());
    }
    // test receive()
    MessageConsumer consumer = store.getConsumer();
    for (int i = 0; i < 10; i++) {
        assertEquals("ID" + i, consumer.receive().getMessageID());
        consumer.ack();
    }
    populateStore(store, 10);
    // test remove()
    for (int i = 0; i < 10; i++) {
        assertEquals("ID" + i, store.remove().getMessageID());
    }
    try {
        store.remove();
        fail();
    } catch (NoSuchElementException expected) {
    }
    populateStore(store, 10);
    // test clear()
    assertEquals(10, store.size());
    store.clear();
    assertEquals(0, store.size());
}
Also used : MessageConsumer(org.apache.synapse.message.MessageConsumer) InMemoryStore(org.apache.synapse.message.store.impl.memory.InMemoryStore) MessageContext(org.apache.synapse.MessageContext) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with InMemoryStore

use of org.apache.synapse.message.store.impl.memory.InMemoryStore in project wso2-synapse by wso2.

the class MessageStoreFactory method createMessageStore.

@SuppressWarnings({ "UnusedDeclaration" })
public static MessageStore createMessageStore(OMElement elem, Properties properties) {
    OMAttribute clss = elem.getAttribute(CLASS_Q);
    MessageStore messageStore;
    if (clss != null) {
        String clssName = clss.getAttributeValue();
        // Make synapse configuration backward compatible
        if (Constants.DEPRECATED_INMEMORY_CLASS.equals(clssName)) {
            clssName = InMemoryStore.class.getName();
        } else if (Constants.DEPRECATED_JMS_CLASS.equals(clssName)) {
            clssName = JmsStore.class.getName();
        }
        try {
            Class cls = Class.forName(clssName);
            messageStore = (MessageStore) cls.newInstance();
        } catch (Exception e) {
            handleException("Error while instantiating the message store", e);
            return null;
        }
    } else {
        messageStore = new InMemoryStore();
    }
    OMAttribute nameAtt = elem.getAttribute(NAME_Q);
    if (nameAtt != null) {
        messageStore.setName(nameAtt.getAttributeValue());
    } else {
        handleException("Message Store name not specified");
    }
    OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
    if (descriptionElem != null) {
        messageStore.setDescription(descriptionElem.getText());
    }
    messageStore.setParameters(getParameters(elem));
    log.info("Successfully added Message Store configuration of : [" + nameAtt.getAttributeValue() + "].");
    return messageStore;
}
Also used : MessageStore(org.apache.synapse.message.store.MessageStore) InMemoryStore(org.apache.synapse.message.store.impl.memory.InMemoryStore) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute) JaxenException(org.jaxen.JaxenException) SynapseException(org.apache.synapse.SynapseException)

Example 4 with InMemoryStore

use of org.apache.synapse.message.store.impl.memory.InMemoryStore in project wso2-synapse by wso2.

the class InMemoryMessageStoreTest method testOrderedDelivery1.

public void testOrderedDelivery1() throws Exception {
    System.out.println("Testing InMemoryStore Ordered Delivery...");
    MessageStore store = new InMemoryStore();
    for (int i = 0; i < 100; i++) {
        store.getProducer().storeMessage(createMessageContext("ID" + i));
    }
    MessageConsumer consumer = store.getConsumer();
    for (int i = 0; i < 100; i++) {
        assertEquals("ID" + i, consumer.receive().getMessageID());
        consumer.ack();
    }
}
Also used : MessageConsumer(org.apache.synapse.message.MessageConsumer) InMemoryStore(org.apache.synapse.message.store.impl.memory.InMemoryStore)

Aggregations

InMemoryStore (org.apache.synapse.message.store.impl.memory.InMemoryStore)4 MessageConsumer (org.apache.synapse.message.MessageConsumer)3 MessageContext (org.apache.synapse.MessageContext)2 NoSuchElementException (java.util.NoSuchElementException)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 SynapseException (org.apache.synapse.SynapseException)1 MessageStore (org.apache.synapse.message.store.MessageStore)1 JaxenException (org.jaxen.JaxenException)1