odbozhou commented on a change in pull request #1210: [ISSUE #1199] Implement 
the 1.0.0 openmessaging consumer API for rocketmq oms module
URL: https://github.com/apache/rocketmq/pull/1210#discussion_r285386039
 
 

 ##########
 File path: 
openmessaging/src/main/java/io/openmessaging/rocketmq/consumer/PullConsumerImpl.java
 ##########
 @@ -76,110 +93,268 @@ public PullConsumerImpl(final KeyValue properties) {
 
         String consumerId = OMSUtil.buildInstanceName();
         this.rocketmqPullConsumer.setInstanceName(consumerId);
-        properties.put(OMSBuiltinKeys.CONSUMER_ID, consumerId);
+        properties.put("CONSUMER_ID", consumerId);
 
         this.rocketmqPullConsumer.setLanguage(LanguageCode.OMS);
 
         this.localMessageCache = new 
LocalMessageCache(this.rocketmqPullConsumer, clientConfig);
+
+        consumerInterceptors = new ArrayList<>(16);
+    }
+
+    private void registerPullTaskCallback(final String targetQueueName) {
+        
this.pullConsumerScheduleService.registerPullTaskCallback(targetQueueName, new 
PullTaskCallback() {
+            @Override
+            public void doPullTask(final MessageQueue mq, final 
PullTaskContext context) {
+                MQPullConsumer consumer = context.getPullConsumer();
+                try {
+                    long offset = localMessageCache.nextPullOffset(mq);
+
+                    PullResult pullResult = consumer.pull(mq, "*",
+                            offset, localMessageCache.nextPullBatchNums());
+                    ProcessQueue pq = 
rocketmqPullConsumer.getDefaultMQPullConsumerImpl().getRebalanceImpl()
+                            .getProcessQueueTable().get(mq);
+                    switch (pullResult.getPullStatus()) {
+                        case FOUND:
+                            if (pq != null) {
+                                pq.putMessage(pullResult.getMsgFoundList());
+                                for (final MessageExt messageExt : 
pullResult.getMsgFoundList()) {
+                                    localMessageCache.submitConsumeRequest(new 
ConsumeRequest(messageExt, mq, pq));
+                                }
+                            }
+                            break;
+                        default:
+                            break;
+                    }
+                    localMessageCache.updatePullOffset(mq, 
pullResult.getNextBeginOffset());
+                } catch (Exception e) {
+                    log.error("A error occurred in pull message process.", e);
+                }
+            }
+        });
     }
 
     @Override
-    public KeyValue attributes() {
-        return properties;
+    public void resume() {
+        currentState = ServiceLifeState.STARTED;
     }
 
     @Override
-    public PullConsumer attachQueue(String queueName) {
-        registerPullTaskCallback(queueName);
-        return this;
+    public void suspend() {
+        currentState = ServiceLifeState.STOPPED;
     }
 
     @Override
-    public PullConsumer attachQueue(String queueName, KeyValue attributes) {
+    public void suspend(long timeout) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isSuspended() {
+        if (ServiceLifeState.STOPPED.equals(currentState)) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void bindQueue(String queueName) {
         registerPullTaskCallback(queueName);
-        return this;
     }
 
     @Override
-    public PullConsumer detachQueue(String queueName) {
+    public void bindQueue(List<String> queueNames) {
+        for (String queueName : queueNames) {
+            bindQueue(queueName);
+        }
+    }
+
+    @Override
+    public void bindQueue(String queueName, MessageListener listener) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void bindQueues(List<String> queueNames, MessageListener listener) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void bindQueue(String queueName, BatchMessageListener listener) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void bindQueues(List<String> queueNames, BatchMessageListener 
listener) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void unbindQueue(String queueName) {
         this.rocketmqPullConsumer.getRegisterTopics().remove(queueName);
-        return this;
     }
 
     @Override
-    public Message receive() {
-        MessageExt rmqMsg = localMessageCache.poll();
+    public void unbindQueues(List<String> queueNames) {
+        for (String queueName : queueNames) {
+            this.rocketmqPullConsumer.getRegisterTopics().remove(queueName);
+        }
+    }
+
+    @Override
+    public boolean isBindQueue() {
+        Set<String> registerTopics = rocketmqPullConsumer.getRegisterTopics();
+        if (null == registerTopics || registerTopics.isEmpty()) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public List<String> getBindQueues() {
+        Set<String> registerTopics = rocketmqPullConsumer.getRegisterTopics();
+        return new ArrayList<>(registerTopics);
+    }
+
+    @Override
+    public void addInterceptor(ConsumerInterceptor interceptor) {
+        consumerInterceptors.add(interceptor);
+    }
+
+    @Override
+    public void removeInterceptor(ConsumerInterceptor interceptor) {
+        consumerInterceptors.remove(interceptor);
+    }
+
+    @Override
+    public Message receive(long timeout) {
+        KeyValue properties = new DefaultKeyValue();
+        properties.put("TIMEOUT", timeout);
+        MessageExt rmqMsg = localMessageCache.poll(properties);
         return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
     }
 
     @Override
-    public Message receive(final KeyValue properties) {
+    public Message receive(String queueName, int partitionId, long receiptId, 
long timeout) {
+        KeyValue properties = new DefaultKeyValue();
+        properties.put("QUEUE_NAME", queueName);
 
 Review comment:
   It has been modified

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to