Search in sources :

Example 1 with Replicator

use of org.apache.rocketmq.connect.activemq.Replicator in project rocketmq-externals by apache.

the class ActivemqSourceTaskTest method pollTest.

@Test
public void pollTest() throws Exception {
    ActivemqSourceTask task = new ActivemqSourceTask();
    TextMessage textMessage = new ActiveMQTextMessage();
    textMessage.setText("hello rocketmq");
    Replicator replicatorObject = Mockito.mock(Replicator.class);
    BlockingQueue<Message> queue = new LinkedBlockingQueue<>();
    Mockito.when(replicatorObject.getQueue()).thenReturn(queue);
    Field replicator = ActivemqSourceTask.class.getDeclaredField("replicator");
    replicator.setAccessible(true);
    replicator.set(task, replicatorObject);
    Field config = ActivemqSourceTask.class.getDeclaredField("config");
    config.setAccessible(true);
    config.set(task, new Config());
    queue.put(textMessage);
    Collection<SourceDataEntry> list = task.poll();
    Assert.assertEquals(list.size(), 1);
    list = task.poll();
    Assert.assertEquals(list.size(), 0);
}
Also used : Field(java.lang.reflect.Field) SourceDataEntry(io.openmessaging.connector.api.data.SourceDataEntry) ActiveMQBytesMessage(org.apache.activemq.command.ActiveMQBytesMessage) MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage) Message(javax.jms.Message) ActiveMQMapMessage(org.apache.activemq.command.ActiveMQMapMessage) TextMessage(javax.jms.TextMessage) StreamMessage(javax.jms.StreamMessage) BytesMessage(javax.jms.BytesMessage) ActiveMQStreamMessage(org.apache.activemq.command.ActiveMQStreamMessage) Config(org.apache.rocketmq.connect.activemq.Config) Replicator(org.apache.rocketmq.connect.activemq.Replicator) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 2 with Replicator

use of org.apache.rocketmq.connect.activemq.Replicator in project rocketmq-externals by apache.

the class ActivemqSourceTask method start.

@Override
public void start(KeyValue props) {
    try {
        this.config = new Config();
        this.config.load(props);
        this.sourcePartition = ByteBuffer.wrap(config.getActivemqUrl().getBytes("UTF-8"));
        this.replicator = new Replicator(config);
        this.replicator.start();
    } catch (Exception e) {
        log.error("activemq task start failed.", e);
        throw new DataConnectException(ErrorCode.START_ERROR_CODE, e.getMessage(), e);
    }
}
Also used : DataConnectException(io.openmessaging.connector.api.exception.DataConnectException) Config(org.apache.rocketmq.connect.activemq.Config) Replicator(org.apache.rocketmq.connect.activemq.Replicator) JMSException(javax.jms.JMSException) DataConnectException(io.openmessaging.connector.api.exception.DataConnectException)

Aggregations

Config (org.apache.rocketmq.connect.activemq.Config)2 Replicator (org.apache.rocketmq.connect.activemq.Replicator)2 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)1 DataConnectException (io.openmessaging.connector.api.exception.DataConnectException)1 Field (java.lang.reflect.Field)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 BytesMessage (javax.jms.BytesMessage)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 Message (javax.jms.Message)1 ObjectMessage (javax.jms.ObjectMessage)1 StreamMessage (javax.jms.StreamMessage)1 TextMessage (javax.jms.TextMessage)1 ActiveMQBytesMessage (org.apache.activemq.command.ActiveMQBytesMessage)1 ActiveMQMapMessage (org.apache.activemq.command.ActiveMQMapMessage)1 ActiveMQObjectMessage (org.apache.activemq.command.ActiveMQObjectMessage)1 ActiveMQStreamMessage (org.apache.activemq.command.ActiveMQStreamMessage)1 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)1 Test (org.junit.Test)1