Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
09aeea34
R
Rocketmq
项目概览
小五666\n哈哈
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
09aeea34
编写于
5月 16, 2019
作者:
O
odbozhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve the oms-1.0.0 consumer implementation
上级
6f3d6097
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
104 addition
and
84 deletion
+104
-84
openmessaging/src/main/java/io/openmessaging/rocketmq/MessagingAccessPointImpl.java
...a/io/openmessaging/rocketmq/MessagingAccessPointImpl.java
+54
-43
openmessaging/src/main/java/io/openmessaging/rocketmq/consumer/LocalMessageCache.java
...io/openmessaging/rocketmq/consumer/LocalMessageCache.java
+13
-4
openmessaging/src/main/java/io/openmessaging/rocketmq/consumer/PullConsumerImpl.java
.../io/openmessaging/rocketmq/consumer/PullConsumerImpl.java
+15
-10
openmessaging/src/main/java/io/openmessaging/rocketmq/consumer/PushConsumerImpl.java
.../io/openmessaging/rocketmq/consumer/PushConsumerImpl.java
+8
-5
openmessaging/src/main/java/io/openmessaging/rocketmq/domain/MessageHeader.java
.../java/io/openmessaging/rocketmq/domain/MessageHeader.java
+1
-1
openmessaging/src/main/java/io/openmessaging/rocketmq/domain/NonStandardKeys.java
...ava/io/openmessaging/rocketmq/domain/NonStandardKeys.java
+1
-1
openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/PullConsumerImplTest.java
...openmessaging/rocketmq/consumer/PullConsumerImplTest.java
+11
-17
openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/PushConsumerImplTest.java
...openmessaging/rocketmq/consumer/PushConsumerImplTest.java
+1
-3
未找到文件。
openmessaging/src/main/java/io/openmessaging/rocketmq/MessagingAccessPointImpl.java
浏览文件 @
09aeea34
...
...
@@ -23,9 +23,9 @@ import io.openmessaging.manager.ResourceManager;
import
io.openmessaging.message.MessageFactory
;
import
io.openmessaging.producer.Producer
;
import
io.openmessaging.producer.TransactionStateCheckListener
;
import
io.openmessaging.rocketmq.consumer.PullConsumerImpl
;
import
io.openmessaging.rocketmq.consumer.PushConsumerImpl
;
import
io.openmessaging.rocketmq.producer.ProducerImpl
;
import
java.util.HashSet
;
import
java.util.Set
;
...
...
@@ -57,65 +57,76 @@ public class MessagingAccessPointImpl implements MessagingAccessPoint {
}
@Override
public
Consumer
createConsumer
()
{
String
consumerId
=
accessPointProperties
.
getString
(
"CONSUMER_ID"
);
String
[]
nsStrArr
=
consumerId
.
split
(
"_"
);
if
(
nsStrArr
.
length
<
2
)
{
return
new
PushConsumerImpl
(
accessPointProperties
);
}
if
(
"pull"
.
equals
(
nsStrArr
[
0
]))
{
return
new
PullConsumerImpl
(
accessPointProperties
);
}
return
new
PushConsumerImpl
(
accessPointProperties
);
}
@Override
public
ResourceManager
resourceManager
()
{
return
new
ResourceManager
()
{
DefaultResourceManager
resourceManager
=
new
DefaultResourceManager
();
return
resourceManager
;
}
@Override
public
MessageFactory
messageFactory
()
{
return
null
;
}
@Override
public
void
createNamespace
(
String
nsName
)
{
accessPointProperties
.
put
(
"CONSUMER_ID"
,
nsName
);
}
class
DefaultResourceManager
implements
ResourceManager
{
@Override
public
void
dele
teNamespace
(
String
nsName
)
{
accessPointProperties
.
put
(
"CONSUMER_ID"
,
null
);
}
@Override
public
void
crea
teNamespace
(
String
nsName
)
{
accessPointProperties
.
put
(
"CONSUMER_ID"
,
nsName
);
}
@Override
public
void
switchNamespace
(
String
targetNamespac
e
)
{
accessPointProperties
.
put
(
"CONSUMER_ID"
,
targetNamespace
);
}
@Override
public
void
deleteNamespace
(
String
nsNam
e
)
{
accessPointProperties
.
put
(
"CONSUMER_ID"
,
null
);
}
@Override
public
Set
<
String
>
listNamespaces
()
{
return
new
HashSet
<
String
>()
{
{
add
(
accessPointProperties
.
getString
(
"CONSUMER_ID"
));
}
};
}
@Override
public
void
switchNamespace
(
String
targetNamespace
)
{
accessPointProperties
.
put
(
"CONSUMER_ID"
,
targetNamespace
);
}
@Override
public
void
createQueue
(
String
queueName
)
{
@Override
public
Set
<
String
>
listNamespaces
()
{
return
new
HashSet
<
String
>()
{
{
add
(
accessPointProperties
.
getString
(
"CONSUMER_ID"
));
}
};
}
}
@Override
public
void
createQueue
(
String
queueName
)
{
@Override
public
void
deleteQueue
(
String
queueName
)
{
}
}
@Override
public
void
deleteQueue
(
String
queueName
)
{
@Override
public
Set
<
String
>
listQueues
(
String
nsName
)
{
return
null
;
}
}
@Override
public
void
filter
(
String
queueName
,
String
filterString
)
{
@Override
public
Set
<
String
>
listQueues
(
String
nsName
)
{
return
null
;
}
}
@Override
public
void
filter
(
String
queueName
,
String
filterString
)
{
@Override
public
void
routing
(
String
sourceQueue
,
String
targetQueue
)
{
}
}
};
}
@Override
public
void
routing
(
String
sourceQueue
,
String
targetQueue
)
{
@Override
public
MessageFactory
messageFactory
()
{
return
null
;
}
}
};
}
openmessaging/src/main/java/io/openmessaging/rocketmq/consumer/LocalMessageCache.java
浏览文件 @
09aeea34
...
...
@@ -23,6 +23,19 @@ import io.openmessaging.extension.QueueMetaData;
import
io.openmessaging.rocketmq.config.ClientConfig
;
import
io.openmessaging.rocketmq.config.DefaultQueueMetaData
;
import
io.openmessaging.rocketmq.domain.ConsumeRequest
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TreeMap
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.locks.ReadWriteLock
;
import
org.apache.commons.lang3.reflect.FieldUtils
;
import
org.apache.rocketmq.client.consumer.DefaultMQPullConsumer
;
import
org.apache.rocketmq.client.exception.MQClientException
;
...
...
@@ -35,10 +48,6 @@ import org.apache.rocketmq.common.message.MessageQueue;
import
org.apache.rocketmq.common.utils.ThreadUtils
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
java.util.*
;
import
java.util.concurrent.*
;
import
java.util.concurrent.locks.ReadWriteLock
;
class
LocalMessageCache
implements
ServiceLifecycle
{
private
final
BlockingQueue
<
ConsumeRequest
>
consumeRequestCache
;
private
final
Map
<
String
,
ConsumeRequest
>
consumedRequest
;
...
...
openmessaging/src/main/java/io/openmessaging/rocketmq/consumer/PullConsumerImpl.java
浏览文件 @
09aeea34
...
...
@@ -33,7 +33,17 @@ import io.openmessaging.rocketmq.domain.BytesMessageImpl;
import
io.openmessaging.rocketmq.domain.ConsumeRequest
;
import
io.openmessaging.rocketmq.utils.BeanUtils
;
import
io.openmessaging.rocketmq.utils.OMSUtil
;
import
org.apache.rocketmq.client.consumer.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Set
;
import
org.apache.rocketmq.client.consumer.DefaultMQPullConsumer
;
import
org.apache.rocketmq.client.consumer.MQPullConsumer
;
import
org.apache.rocketmq.client.consumer.MQPullConsumerScheduleService
;
import
org.apache.rocketmq.client.consumer.PullResult
;
import
org.apache.rocketmq.client.consumer.PullStatus
;
import
org.apache.rocketmq.client.consumer.PullTaskCallback
;
import
org.apache.rocketmq.client.consumer.PullTaskContext
;
import
org.apache.rocketmq.client.exception.MQBrokerException
;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.client.impl.consumer.ProcessQueue
;
...
...
@@ -44,11 +54,6 @@ import org.apache.rocketmq.logging.InternalLogger;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.apache.rocketmq.remoting.protocol.LanguageCode
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Set
;
public
class
PullConsumerImpl
implements
Consumer
{
private
final
DefaultMQPullConsumer
rocketmqPullConsumer
;
private
final
KeyValue
properties
;
...
...
@@ -273,16 +278,16 @@ public class PullConsumerImpl implements Consumer {
try
{
pullResult
=
rocketmqPullConsumer
.
pull
(
mq
,
"*"
,
receiptId
,
4
*
1024
*
1024
,
timeout
);
}
catch
(
MQClientException
e
)
{
e
.
printStackTrace
(
);
log
.
error
(
"A error occurred when pull message."
,
e
);
return
null
;
}
catch
(
RemotingException
e
)
{
e
.
printStackTrace
(
);
log
.
error
(
"A error occurred when pull message."
,
e
);
return
null
;
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
(
);
log
.
error
(
"A error occurred when pull message."
,
e
);
return
null
;
}
catch
(
MQBrokerException
e
)
{
e
.
printStackTrace
(
);
log
.
error
(
"A error occurred when pull message."
,
e
);
return
null
;
}
if
(
null
==
pullResult
)
{
...
...
openmessaging/src/main/java/io/openmessaging/rocketmq/consumer/PushConsumerImpl.java
浏览文件 @
09aeea34
...
...
@@ -34,6 +34,14 @@ import io.openmessaging.rocketmq.domain.BytesMessageImpl;
import
io.openmessaging.rocketmq.domain.NonStandardKeys
;
import
io.openmessaging.rocketmq.utils.BeanUtils
;
import
io.openmessaging.rocketmq.utils.OMSUtil
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.rocketmq.client.consumer.DefaultMQPushConsumer
;
import
org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext
;
import
org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus
;
...
...
@@ -45,11 +53,6 @@ import org.apache.rocketmq.common.message.MessageQueue;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.remoting.protocol.LanguageCode
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
public
class
PushConsumerImpl
implements
Consumer
{
private
final
static
InternalLogger
log
=
ClientLogger
.
getLog
();
...
...
openmessaging/src/main/java/io/openmessaging/rocketmq/domain/MessageHeader.java
浏览文件 @
09aeea34
...
...
@@ -18,7 +18,7 @@ package io.openmessaging.rocketmq.domain;
import
io.openmessaging.message.Header
;
public
class
MessageHeader
implements
Header
{
public
class
MessageHeader
implements
Header
{
private
String
destination
;
...
...
openmessaging/src/main/java/io/openmessaging/rocketmq/domain/NonStandardKeys.java
浏览文件 @
09aeea34
...
...
@@ -28,5 +28,5 @@ public interface NonStandardKeys {
String
PULL_MESSAGE_BATCH_NUMS
=
"rmq.pull.message.batch.nums"
;
String
PULL_MESSAGE_CACHE_CAPACITY
=
"rmq.pull.message.cache.capacity"
;
String
PRODUCER_ID
=
"PRODUCER_ID"
;
String
CONSUMER_ID
=
"CONSUMER_ID"
;
String
CONSUMER_ID
=
"CONSUMER_ID"
;
}
openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/PullConsumerImplTest.java
浏览文件 @
09aeea34
...
...
@@ -16,12 +16,15 @@
*/
package
io.openmessaging.rocketmq.consumer
;
import
io.openmessaging.*
;
import
io.openmessaging.KeyValue
;
import
io.openmessaging.MessagingAccessPoint
;
import
io.openmessaging.OMS
;
import
io.openmessaging.consumer.Consumer
;
import
io.openmessaging.manager.ResourceManager
;
import
io.openmessaging.message.Message
;
import
io.openmessaging.rocketmq.config.ClientConfig
;
import
io.openmessaging.rocketmq.domain.NonStandardKeys
;
import
java.lang.reflect.Field
;
import
org.apache.rocketmq.client.consumer.DefaultMQPullConsumer
;
import
org.apache.rocketmq.common.message.MessageExt
;
import
org.junit.Before
;
...
...
@@ -30,11 +33,10 @@ import org.junit.runner.RunWith;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.lang.reflect.Field
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
spy
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
PullConsumerImplTest
{
...
...
@@ -49,11 +51,9 @@ public class PullConsumerImplTest {
public
void
init
()
throws
NoSuchFieldException
,
IllegalAccessException
{
final
MessagingAccessPoint
messagingAccessPoint
=
OMS
.
getMessagingAccessPoint
(
"oms:rocketmq://IP1:9876,IP2:9876/namespace"
);
final
KeyValue
attributes
=
messagingAccessPoint
.
attributes
();
final
ResourceManager
resourceManager
=
messagingAccessPoint
.
resourceManager
();
resourceManager
.
createNamespace
(
"TestGroup"
);
resourceManager
.
createNamespace
(
"
pull_
TestGroup"
);
consumer
=
messagingAccessPoint
.
createConsumer
();
// consumer = messagingAccessPoint.createPullConsumer(OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "TestGroup"));
consumer
.
bindQueue
(
queueName
);
Field
field
=
PullConsumerImpl
.
class
.
getDeclaredField
(
"rocketmqPullConsumer"
);
...
...
@@ -78,9 +78,7 @@ public class PullConsumerImplTest {
consumedMsg
.
setBody
(
testBody
);
consumedMsg
.
putUserProperty
(
NonStandardKeys
.
MESSAGE_DESTINATION
,
"TOPIC"
);
consumedMsg
.
setTopic
(
queueName
);
when
(
localMessageCache
.
poll
()).
thenReturn
(
consumedMsg
);
doReturn
(
consumedMsg
).
when
(
localMessageCache
).
poll
(
any
(
KeyValue
.
class
));
Message
message
=
consumer
.
receive
(
3
*
1000
);
assertThat
(
message
.
header
().
getMessageId
()).
isEqualTo
(
"NewMsgId"
);
assertThat
(
message
.
getData
()).
isEqualTo
(
testBody
);
...
...
@@ -88,11 +86,7 @@ public class PullConsumerImplTest {
@Test
public
void
testPoll_WithTimeout
()
{
// There is a default timeout value, @see ClientConfig#omsOperationTimeout.
// Message message = consumer.receive(3 * 1000);
// assertThat(message).isNull();
// message = consumer.receive(OMS.newKeyValue().put(Message.BuiltinKeys.TIMEOUT, 100));
// assertThat(message).isNull();
Message
message
=
consumer
.
receive
(
3
*
1000
);
assertThat
(
message
).
isNull
();
}
}
\ No newline at end of file
openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/PushConsumerImplTest.java
浏览文件 @
09aeea34
...
...
@@ -48,10 +48,8 @@ public class PushConsumerImplTest {
public
void
init
()
throws
NoSuchFieldException
,
IllegalAccessException
{
final
MessagingAccessPoint
messagingAccessPoint
=
OMS
.
getMessagingAccessPoint
(
"oms:rocketmq://IP1:9876,IP2:9876/namespace"
);
/* consumer = messagingAccessPoint.createPushConsumer(
OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "TestGroup"));*/
final
ResourceManager
resourceManager
=
messagingAccessPoint
.
resourceManager
();
resourceManager
.
createNamespace
(
"TestGroup"
);
resourceManager
.
createNamespace
(
"
push_
TestGroup"
);
consumer
=
messagingAccessPoint
.
createConsumer
();
Field
field
=
PushConsumerImpl
.
class
.
getDeclaredField
(
"rocketmqPushConsumer"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录