Skip to content

Commit

Permalink
update rocketmq starter example
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Dec 24, 2017
1 parent dfe334f commit 0fc2d1b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 50 deletions.
10 changes: 5 additions & 5 deletions spring-boot-rocketmq/pom.xml
Expand Up @@ -18,15 +18,15 @@
</dependency>

<dependency>
<groupId>com.rhwayfun</groupId>
<groupId>io.github.rhwayfun</groupId>
<artifactId>spring-boot-rocketmq-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.3.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>

Expand Down
@@ -1,6 +1,6 @@
package com.rhwayfun.springboot.rocketmq.mq;

import com.rhwayfun.springboot.rocketmq.starter.common.AbstractRocketMqConsumer;
import io.github.rhwayfun.springboot.rocketmq.starter.common.AbstractRocketMqConsumer;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.stereotype.Component;

Expand All @@ -15,7 +15,7 @@
*/
@Component
public class DemoRocketMqConsumerExample
extends AbstractRocketMqConsumer<DemoRocketMqTopic, DemoRocketMqTag, DemoRocketMqContent> {
extends AbstractRocketMqConsumer<DemoRocketMqTopic, DemoRocketMqContent> {

@Override
public Map<String, Set<String>> subscribeTopicTags() {
Expand All @@ -28,9 +28,13 @@ public Map<String, Set<String>> subscribeTopicTags() {
}

@Override
public boolean handle(String topic, String tag, DemoRocketMqContent content, MessageExt msg) {
logger.info("receive msg[{}], topic:{}, tag:{}, content:{}", msg, topic, tag, content);
return true;
public String getConsumerGroup() {
return "spring-boot-test-consumer-group";
}

@Override
public boolean consumeMsg(DemoRocketMqContent content, MessageExt msg) {
logger.info("receive msg[{}], topic:{}, tag:{}, content:{}", msg, content);
return false;
}
}
@@ -1,6 +1,7 @@
package com.rhwayfun.springboot.rocketmq.mq;

import com.rhwayfun.springboot.rocketmq.starter.constants.RocketMqContent;

import io.github.rhwayfun.springboot.rocketmq.starter.constants.RocketMqContent;

/**
* @author rhwayfun
Expand Down
@@ -0,0 +1,37 @@
package com.rhwayfun.springboot.rocketmq.mq;

import io.github.rhwayfun.springboot.rocketmq.starter.common.DefaultRocketMqProducer;
import org.apache.rocketmq.common.message.Message;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Timer;
import java.util.TimerTask;

/**
* @author rhwayfun
* @since 0.0.1
*/
@Component
public class DemoRocketMqProducerExample {

@Resource
private DefaultRocketMqProducer producer;

@PostConstruct
public void execute() {
new Timer().schedule(new TimerTask() {
@Override
public void run() {
DemoRocketMqContent content = new DemoRocketMqContent();
content.setCityId(1);
content.setDesc("城市");
Message msg = new Message("TopicA", "TagA", content.toString().getBytes());
boolean sendResult = producer.sendMsg(msg);
System.out.println("发送结果:" + sendResult);
}
}, 0, 10000);
}

}
@@ -1,6 +1,6 @@
package com.rhwayfun.springboot.rocketmq.mq;

import com.rhwayfun.springboot.rocketmq.starter.constants.RocketMqTag;
import io.github.rhwayfun.springboot.rocketmq.starter.constants.RocketMqTag;

/**
* @author rhwayfun
Expand Down
@@ -1,6 +1,6 @@
package com.rhwayfun.springboot.rocketmq.mq;

import com.rhwayfun.springboot.rocketmq.starter.constants.RocketMqTopic;
import io.github.rhwayfun.springboot.rocketmq.starter.constants.RocketMqTopic;

/**
* @author rhwayfun
Expand Down

This file was deleted.

Expand Up @@ -2,4 +2,4 @@ spring.application.name=spring-boot-rocketmq

# Apache RocketMQ
spring.rocketmq.nameServer=localhost:9876
spring.rocketmq.consumerGroupName=spring-boot-rocketmq-consumer-group
spring.rocketmq.producer-group-name=spring-boot-test-producer-group

0 comments on commit 0fc2d1b

Please sign in to comment.