本文整理汇总了Java中com.alibaba.rocketmq.common.UtilAll类的典型用法代码示例。如果您正苦于以下问题:Java UtilAll类的具体用法?Java UtilAll怎么用?Java UtilAll使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UtilAll类属于com.alibaba.rocketmq.common包,在下文中一共展示了UtilAll类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: checkTopic
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* Validate topic
*
* @param topic
* @throws com.alibaba.rocketmq.client.exception.MQClientException
*/
public static void checkTopic(String topic) throws MQClientException {
if (UtilAll.isBlank(topic)) {
throw new MQClientException("the specified topic is blank", null);
}
if (!regularExpressionMatcher(topic, PATTERN)) {
throw new MQClientException(String.format(
"the specified topic[%s] contains illegal characters, allowing only %s", topic,
VALID_PATTERN_STR), null);
}
if (topic.length() > CHARACTER_MAX_LENGTH) {
throw new MQClientException("the specified topic is longer than topic max length 255.", null);
}
//whether the same with system reserved keyword
if (topic.equals(MixAll.DEFAULT_TOPIC)) {
throw new MQClientException(
String.format("the topic[%s] is conflict with default topic.", topic), null);
}
}
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:28,代码来源:Validators.java
示例2: tryToCompressMessage
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
private boolean tryToCompressMessage(final Message msg) {
byte[] body = msg.getBody();
if (body != null) {
if (body.length >= this.defaultMQProducer.getCompressMsgBodyOverHowmuch()) {
try {
byte[] data = UtilAll.compress(body, zipCompressLevel);
if (data != null) {
msg.setBody(data);
return true;
}
}
catch (IOException e) {
log.error("tryToCompressMessage exception", e);
log.warn(msg.toString());
}
}
}
return false;
}
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:21,代码来源:DefaultMQProducerImpl.java
示例3: getConsumerRunningInfo
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
final GetConsumerRunningInfoRequestHeader requestHeader =
(GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class);
ConsumerRunningInfo consumerRunningInfo = this.mqClientFactory.consumerRunningInfo(requestHeader.getConsumerGroup());
if (null != consumerRunningInfo) {
if (requestHeader.isJstackEnable()) {
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
consumerRunningInfo.setStackTraceElementMap(map);
String jstack = UtilAll.jstack(map);
consumerRunningInfo.setJstack(jstack);
}
response.setCode(ResponseCode.SUCCESS);
response.setBody(consumerRunningInfo.encode());
}
else {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
}
return response;
}
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:25,代码来源:ClientRemotingProcessor.java
示例4: StoreCheckpoint
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
public StoreCheckpoint(final String scpPath) throws IOException {
File file = new File(scpPath);
MapedFile.ensureDirOK(file.getParent());
boolean fileExists = file.exists();
this.randomAccessFile = new RandomAccessFile(file, "rw");
this.fileChannel = this.randomAccessFile.getChannel();
this.mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0, MapedFile.OS_PAGE_SIZE);
if (fileExists) {
log.info("store checkpoint file exists, " + scpPath);
this.physicMsgTimestamp = this.mappedByteBuffer.getLong(0);
this.logicsMsgTimestamp = this.mappedByteBuffer.getLong(8);
this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16);
log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", "
+ UtilAll.timeMillisToHumanString(this.physicMsgTimestamp));
log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", "
+ UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp));
log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", "
+ UtilAll.timeMillisToHumanString(this.indexMsgTimestamp));
}
else {
log.info("store checkpoint file not exists, " + scpPath);
}
}
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:27,代码来源:StoreCheckpoint.java
示例5: tryToCompressMessage
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* 尝试压缩消息
* 如果消息内容超过了规定的大小(默认4KB),就会进行压缩
*
* @param msg
* @return
*/
private boolean tryToCompressMessage(final Message msg) {
byte[] body = msg.getBody();
if (body != null) {
if (body.length >= this.defaultMQProducer.getCompressMsgBodyOverHowmuch()) {
try {
byte[] data = UtilAll.compress(body, zipCompressLevel);
if (data != null) {
msg.setBody(data);
return true;
}
} catch (IOException e) {
log.error("tryToCompressMessage exception", e);
log.warn(msg.toString());
}
}
}
return false;
}
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:27,代码来源:DefaultMQProducerImpl.java
示例6: testStackTrace
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
@Test
public void testStackTrace() {
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
Set<Map.Entry<Thread, StackTraceElement[]>> entries = map.entrySet();
for (Map.Entry<Thread, StackTraceElement[]> entry : entries) {
System.out.println();
System.out.println("-----------------------Thread:" + entry.getKey().toString() + "------------------------------");
StackTraceElement[] value = entry.getValue();
for (int i = 0; i < value.length; i++) {
StackTraceElement stackTraceElement = value[i];
System.out.println(stackTraceElement.toString());
}
}
System.out.println(UtilAll.jstack(map));
}
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:21,代码来源:LocalTest.java
示例7: decodeMessageId
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
public static MessageId decodeMessageId(final String msgId) throws UnknownHostException {
SocketAddress address;
long offset;
byte[] ip = UtilAll.string2bytes(msgId.substring(0, 8));
byte[] port = UtilAll.string2bytes(msgId.substring(8, 16));
ByteBuffer bb = ByteBuffer.wrap(port);
int portInt = bb.getInt(0);
address = new InetSocketAddress(InetAddress.getByAddress(ip), portInt);
// offset
byte[] data = UtilAll.string2bytes(msgId.substring(16, 32));
bb = ByteBuffer.wrap(data);
offset = bb.getLong(0);
return new MessageId(address, offset);
}
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:18,代码来源:MessageDecoder.java
示例8: checkTopic
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* topic 有效性检查
*
* @param topic
* @throws com.alibaba.rocketmq.client.exception.MQClientException
*/
public static void checkTopic(String topic) throws MQClientException {
if (UtilAll.isBlank(topic)) {
throw new MQClientException("the specified topic is blank", null);
}
if (!regularExpressionMatcher(topic, PATTERN)) {
throw new MQClientException(String.format(
"the specified topic[%s] contains illegal characters, allowing only %s", topic,
VALID_PATTERN_STR), null);
}
if (topic.length() > CHARACTER_MAX_LENGTH) {
throw new MQClientException("the specified topic is longer than topic max length 255.", null);
}
// Topic名字是否与保留字段冲突
if (topic.equals(MixAll.DEFAULT_TOPIC)) {
throw new MQClientException(
String.format("the topic[%s] is conflict with default topic.", topic), null);
}
}
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:26,代码来源:Validators.java
示例9: updateConsumerOffsetOneway
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* 更新Consumer消费进度
*
* @throws InterruptedException
* @throws RemotingSendRequestException
* @throws RemotingTimeoutException
* @throws RemotingTooMuchRequestException
*
* @throws RemotingConnectException
*/
public void updateConsumerOffsetOneway(//
final String addr,//
final UpdateConsumerOffsetRequestHeader requestHeader,//
final long timeoutMillis//
) throws RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException,
RemotingSendRequestException, InterruptedException {
// 添加虚拟运行环境相关的projectGroupPrefix
if (!UtilAll.isBlank(projectGroupPrefix)) {
requestHeader.setConsumerGroup(VirtualEnvUtil.buildWithProjectGroup(
requestHeader.getConsumerGroup(), projectGroupPrefix));
requestHeader.setTopic(VirtualEnvUtil.buildWithProjectGroup(requestHeader.getTopic(),
projectGroupPrefix));
}
RemotingCommand request =
RemotingCommand.createRequestCommand(RequestCode.UPDATE_CONSUMER_OFFSET, requestHeader);
this.remotingClient.invokeOneway(addr, request, timeoutMillis);
}
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:30,代码来源:MQClientAPIImpl.java
示例10: endTransactionOneway
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* 提交或者回滚事务
*/
public void endTransactionOneway(//
final String addr,//
final EndTransactionRequestHeader requestHeader,//
final String remark,//
final long timeoutMillis//
) throws RemotingException, MQBrokerException, InterruptedException {
// 添加虚拟运行环境相关的projectGroupPrefix
if (!UtilAll.isBlank(projectGroupPrefix)) {
requestHeader.setProducerGroup(VirtualEnvUtil.buildWithProjectGroup(
requestHeader.getProducerGroup(), projectGroupPrefix));
}
RemotingCommand request =
RemotingCommand.createRequestCommand(RequestCode.END_TRANSACTION, requestHeader);
request.setRemark(remark);
this.remotingClient.invokeOneway(addr, request, timeoutMillis);
}
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:22,代码来源:MQClientAPIImpl.java
示例11: queryMessage
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* 查询消息
*/
public void queryMessage(//
final String addr,//
final QueryMessageRequestHeader requestHeader,//
final long timeoutMillis,//
final InvokeCallback invokeCallback//
) throws RemotingException, MQBrokerException, InterruptedException {
// 添加虚拟运行环境相关的projectGroupPrefix
if (!UtilAll.isBlank(projectGroupPrefix)) {
requestHeader.setTopic(VirtualEnvUtil.buildWithProjectGroup(requestHeader.getTopic(),
projectGroupPrefix));
}
RemotingCommand request =
RemotingCommand.createRequestCommand(RequestCode.QUERY_MESSAGE, requestHeader);
this.remotingClient.invokeAsync(addr, request, timeoutMillis, invokeCallback);
}
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:21,代码来源:MQClientAPIImpl.java
示例12: decodeMessageId
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
public static MessageId decodeMessageId(final String msgId) throws UnknownHostException {
SocketAddress address;
long offset;
// 地址
byte[] ip = UtilAll.string2bytes(msgId.substring(0, 8));
byte[] port = UtilAll.string2bytes(msgId.substring(8, 16));
ByteBuffer bb = ByteBuffer.wrap(port);
int portInt = bb.getInt(0);
address = new InetSocketAddress(InetAddress.getByAddress(ip), portInt);
// offset
byte[] data = UtilAll.string2bytes(msgId.substring(16, 32));
bb = ByteBuffer.wrap(data);
offset = bb.getLong(0);
return new MessageId(address, offset);
}
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:19,代码来源:MessageDecoder.java
示例13: checkTopic
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* topic 有效性检查
*
* @param topic
* @throws com.alibaba.rocketmq.client.exception.MQClientException
*/
public static void checkTopic(String topic) throws MQClientException {
if (UtilAll.isBlank(topic)) {
throw new MQClientException("the specified topic is blank", null);
}
if (!regularExpressionMatcher(topic, validPatternStr)) {
throw new MQClientException(String.format(
"the specified topic[%s] contains illegal characters, allowing only %s", topic,
validPatternStr), null);
}
if (topic.length() > CHARACTER_MAX_LENGTH) {
throw new MQClientException("the specified topic is longer than topic max length 255.", null);
}
// Topic名字是否与保留字段冲突
if (topic.equals(MixAll.DEFAULT_TOPIC)) {
throw new MQClientException(
String.format("the topic[%s] is conflict with default topic.", topic), null);
}
}
开发者ID:brucechan0921,项目名称:RocketMQ-3.0.8,代码行数:26,代码来源:Validators.java
示例14: updateConsumerOffsetOneway
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* 更新Consumer消费进度
*
* @throws InterruptedException
* @throws RemotingSendRequestException
* @throws RemotingTimeoutException
* @throws RemotingTooMuchRequestException
*
* @throws RemotingConnectException
*/
public void updateConsumerOffsetOneway(//
final String addr,//
final UpdateConsumerOffsetRequestHeader requestHeader,//
final long timeoutMillis//
) throws RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException,
RemotingSendRequestException, InterruptedException {
// 添加虚拟运行环境相关的projectGroupPrefix
if (!UtilAll.isBlank(projectGroupPrefix)) {
requestHeader.setConsumerGroup(VirtualEnvUtil.buildWithProjectGroup(
requestHeader.getConsumerGroup(), projectGroupPrefix));
requestHeader.setTopic(VirtualEnvUtil.buildWithProjectGroup(requestHeader.getTopic(),
projectGroupPrefix));
}
RemotingCommand request =
RemotingCommand.createRequestCommand(MQRequestCode.UPDATE_CONSUMER_OFFSET_VALUE,
requestHeader);
this.remotingClient.invokeOneway(addr, request, timeoutMillis);
}
开发者ID:brucechan0921,项目名称:RocketMQ-3.0.8,代码行数:30,代码来源:MQClientAPIImpl.java
示例15: endTransactionOneway
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* 提交或者回滚事务
*/
public void endTransactionOneway(//
final String addr,//
final EndTransactionRequestHeader requestHeader,//
final String remark,//
final long timeoutMillis//
) throws RemotingException, MQBrokerException, InterruptedException {
// 添加虚拟运行环境相关的projectGroupPrefix
if (!UtilAll.isBlank(projectGroupPrefix)) {
requestHeader.setProducerGroup(VirtualEnvUtil.buildWithProjectGroup(
requestHeader.getProducerGroup(), projectGroupPrefix));
}
RemotingCommand request =
RemotingCommand.createRequestCommand(MQRequestCode.END_TRANSACTION_VALUE, requestHeader);
request.setRemark(remark);
this.remotingClient.invokeOneway(addr, request, timeoutMillis);
}
开发者ID:brucechan0921,项目名称:RocketMQ-3.0.8,代码行数:21,代码来源:MQClientAPIImpl.java
示例16: queryMessage
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* 查询消息
*/
public void queryMessage(//
final String addr,//
final QueryMessageRequestHeader requestHeader,//
final long timeoutMillis,//
final InvokeCallback invokeCallback//
) throws RemotingException, MQBrokerException, InterruptedException {
// 添加虚拟运行环境相关的projectGroupPrefix
if (!UtilAll.isBlank(projectGroupPrefix)) {
requestHeader.setTopic(VirtualEnvUtil.buildWithProjectGroup(requestHeader.getTopic(),
projectGroupPrefix));
}
RemotingCommand request =
RemotingCommand.createRequestCommand(MQRequestCode.QUERY_MESSAGE_VALUE, requestHeader);
this.remotingClient.invokeAsync(addr, request, timeoutMillis, invokeCallback);
}
开发者ID:brucechan0921,项目名称:RocketMQ-3.0.8,代码行数:20,代码来源:MQClientAPIImpl.java
示例17: registerClient
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
public boolean registerClient(final String addr, final HeartbeatData heartbeat, final long timeoutMillis)
throws RemotingException, InterruptedException {
// 添加虚拟运行环境相关的projectGroupPrefix
if (!UtilAll.isBlank(projectGroupPrefix)) {
Set<ConsumerData> consumerDatas = heartbeat.getConsumerDataSet();
for (ConsumerData consumerData : consumerDatas) {
consumerData.setGroupName(VirtualEnvUtil.buildWithProjectGroup(consumerData.getGroupName(),
projectGroupPrefix));
Set<SubscriptionData> subscriptionDatas = consumerData.getSubscriptionDataSet();
for (SubscriptionData subscriptionData : subscriptionDatas) {
subscriptionData.setTopic(VirtualEnvUtil.buildWithProjectGroup(
subscriptionData.getTopic(), projectGroupPrefix));
}
}
Set<ProducerData> producerDatas = heartbeat.getProducerDataSet();
for (ProducerData producerData : producerDatas) {
producerData.setGroupName(VirtualEnvUtil.buildWithProjectGroup(producerData.getGroupName(),
projectGroupPrefix));
}
}
RemotingCommand request = RemotingCommand.createRequestCommand(MQRequestCode.HEART_BEAT_VALUE, null);
request.setBody(heartbeat.encode());
RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
return response.getCode() == ResponseCode.SUCCESS_VALUE;
}
开发者ID:brucechan0921,项目名称:RocketMQ-3.0.8,代码行数:27,代码来源:MQClientAPIImpl.java
示例18: checkGroup
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
/**
* Validate group
*
* @param group
* @throws com.alibaba.rocketmq.client.exception.MQClientException
*/
public static void checkGroup(String group) throws MQClientException {
if (UtilAll.isBlank(group)) {
throw new MQClientException("the specified group is blank", null);
}
if (!regularExpressionMatcher(group, PATTERN)) {
throw new MQClientException(String.format(
"the specified group[%s] contains illegal characters, allowing only %s", group,
VALID_PATTERN_STR), null);
}
if (group.length() > CHARACTER_MAX_LENGTH) {
throw new MQClientException("the specified group is longer than group max length 255.", null);
}
}
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:20,代码来源:Validators.java
示例19: sendMessageBack
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName)
throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
try {
String brokerAddr =
(null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
: RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
//结合结合SendMessageProcessor.consumerSendMsgBack阅读
//消费失败,重新打回消息到broker中 这里发送的报文的code:CONSUMER_SEND_MSG_BACK,对端收到后,会创建重试队列RETRY_GROUP_TOPIC_PREFIX + consumer
this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg,
this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000);
}
catch (Exception e) { //消费失败的消息打回重试队列失败,,需要重新发送到重试队列
log.error("sendMessageBack Exception, " + this.defaultMQPushConsumer.getConsumerGroup(), e);
//这里发送的报文code默认为code:SEND_MESSAGE,因此需要带上重试队列名,对于broker来说就相当于收到了一条发往RETRY_GROUP_TOPIC_PREFIX + consumer的消息
Message newMsg =
//修改topic,修改后的topic为 RETRY_GROUP_TOPIC_PREFIX + consumer 需要重新发送
new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()),
msg.getBody());
String originMsgId = MessageAccessor.getOriginMessageId(msg);
MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId()
: originMsgId);
newMsg.setFlag(msg.getFlag());
MessageAccessor.setProperties(newMsg, msg.getProperties());
MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
int reTimes = msg.getReconsumeTimes() + 1;
MessageAccessor.setReconsumeTime(newMsg, reTimes + "");
newMsg.setDelayTimeLevel(3 + reTimes);
this.mQClientFactory.getDefaultMQProducer().send(newMsg);
}
}
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:36,代码来源:DefaultMQPushConsumerImpl.java
示例20: sendMessageBack
import com.alibaba.rocketmq.common.UtilAll; //导入依赖的package包/类
public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName, String consumerGroup)
throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
try {
String brokerAddr =
(null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
: RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
if (UtilAll.isBlank(consumerGroup)) {
consumerGroup = this.defaultMQPullConsumer.getConsumerGroup();
}
this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg, consumerGroup,
delayLevel, 3000);
} catch (Exception e) {
log.error("sendMessageBack Exception, " + this.defaultMQPullConsumer.getConsumerGroup(), e);
Message newMsg =
new Message(MixAll.getRetryTopic(this.defaultMQPullConsumer.getConsumerGroup()),
msg.getBody());
newMsg.setFlag(msg.getFlag());
MessageAccessor.setProperties(newMsg, msg.getProperties());
MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
this.mQClientFactory.getDefaultMQProducer().send(newMsg);
}
}
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:28,代码来源:DefaultMQPullConsumerImpl.java
注:本文中的com.alibaba.rocketmq.common.UtilAll类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论