Commit a551176b by QIANGLU

更新rocketmq

parent 138eb5e8
package com.matrix.grpc; package com.matrix.grpc;
import com.takumiCX.greeter.GreeterGrpc; import com.takumiCX.greeter.GreeterGrpc;
import com.takumiCX.greeter.HelloGrpc;
import com.takumiCX.greeter.HelloReply; import com.takumiCX.greeter.HelloReply;
import com.takumiCX.greeter.HelloRequest; import com.takumiCX.greeter.HelloRequest;
import io.grpc.ManagedChannel; import io.grpc.ManagedChannel;
...@@ -24,7 +25,6 @@ public class HelloWordClient { ...@@ -24,7 +25,6 @@ public class HelloWordClient {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost",port).usePlaintext().build(); ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost",port).usePlaintext().build();
GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel); GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel);
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
while(true){ while(true){
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nova</groupId>
<artifactId>spring-boot-rocketmq</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.8.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>logger-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>rocketmq-starter</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
\ No newline at end of file
package com.matrix.pure;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @ClassName RcoketStartup
* @Author QIANGLU
* @Date 2019/11/28 4:00 下午
* @Version 1.0
*/
@SpringBootApplication
public class RcoketStartup {
public static void main(String[] args) {
SpringApplication.run(RcoketStartup.class, args);
}
}
package com.matrix.pure.rocketmq;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.print.DocFlavor;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @ClassName ConsumerListener
* @Author QIANGLU
* @Date 2019/11/28 3:53 下午
* @Version 1.0
*/
@Component
@RocketMQMessageListener(topic = "topic", consumerGroup = "exwarngroup")
public class ConsumerListener implements RocketMQListener<String> {
private final static Logger log = LoggerFactory.getLogger(ConsumerListener.class);
private volatile AtomicInteger count = new AtomicInteger();
@Override
public void onMessage(String message) {
log.info(" consumer count:{}",count.incrementAndGet());
}
}
package com.matrix.pure.rocketmq;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @ClassName SendRocketService
* @Author QIANGLU
* @Date 2019/11/28 3:47 下午
* @Version 1.0
*/
@Component
public class SendRocketDemo implements Runnable {
private Logger logger = LoggerFactory.getLogger(SendRocketDemo.class);
@Resource
private RocketMQTemplate rocketMQTemplate;
private ScheduledFuture<?> scheduledFuture;
private volatile AtomicInteger count = new AtomicInteger();
public SendRocketDemo(){
scheduledFuture = Executors
.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this,0,1,TimeUnit.SECONDS);
}
@Override
public void run() {
//发送 Demo
try {
Message message = new Message();
//设置 body
message.setBody("我是一条测试信息".getBytes());
//设置tag
message.setTags("demo");
//同步发送 第一个参数是topic
SendResult sendResult = rocketMQTemplate.syncSend("topic",message);
//异步发送
rocketMQTemplate.asyncSend("topic",message,null,0);
}catch (Exception e){
logger.error("发送MQ异常",e);
}
}
}
package com.matrix.pure.tcp;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
/**
* @ClassName NettyServer
* @Author QIANGLU
* @Date 2019/12/3 11:31 下午
* @Version 1.0
*/
public class NettyClient {
public static void main(String[] args) throws IOException {
SocketChannel socketChannel = SocketChannel.open();
socketChannel.bind(new InetSocketAddress("localhost", 9999));
ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
byteBuffer.put("this is test ".getBytes());
byteBuffer.flip();
while (byteBuffer.hasRemaining()){
socketChannel.write(byteBuffer);
}
}
}
package com.matrix.pure.tcp;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
/**
* @ClassName NettyServer
* @Author QIANGLU
* @Date 2019/12/3 11:31 下午
* @Version 1.0
*/
public class NettyServer {
public static void main(String[] args) throws IOException {
Selector selector = Selector.open();
ServerSocketChannel socketChannel = ServerSocketChannel.open();
socketChannel.bind(new InetSocketAddress("loclhost", 9999));
socketChannel.configureBlocking(false);
socketChannel.register(selector, SelectionKey.OP_ACCEPT);
while (true) {
selector.select();
Iterator<SelectionKey> selectorIterator = selector.selectedKeys().iterator();
while (selectorIterator.hasNext()){
SelectionKey selectionKey = selectorIterator.next();
if(selectionKey.isAcceptable()){
SocketChannel channel = socketChannel.accept();
channel.configureBlocking(false);
channel.register(selector,SelectionKey.OP_READ,ByteBuffer.allocate(1024));
}
if(selectionKey.isReadable()){
}
}
//
SocketChannel socketChannel1 = socketChannel.accept();
ByteBuffer buffer = ByteBuffer.allocate(1024);
int reder = socketChannel1.read(buffer);
if (reder > 0) {
buffer.flip();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
String body = new String(bytes,"UTF-8");
System.out.println("server 收到:" + body);
}
}
}
}
spring:
application:
name: learn-rocketmq
server:
port: 6080
rocketmq:
name-server: 10.0.254.191:9876;10.0.254.206:9876
producer:
group: learn-rocketmq
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment