Skip to content

Commit

Permalink
Ws 推送完成
Browse files Browse the repository at this point in the history
  • Loading branch information
lmxdawn committed Dec 14, 2021
1 parent 1c2f92a commit 5a7d433
Show file tree
Hide file tree
Showing 61 changed files with 2,289 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ nohup java -jar -Dspring.profiles.active=prod user/target/user-0.0.1-SNAPSHOT.ja
> match:撮合 9008
> ws:消息推送 9009
> ws-route:消息推送路由 9010
# Swagger

> gateway的方式访问swagger,gateway启动后访问: `http://ip:prot/swagger-ui/index.html`
Expand Down Expand Up @@ -69,6 +73,8 @@ nohup java -jar -Dspring.profiles.active=prod user/target/user-0.0.1-SNAPSHOT.ja
> Disruptor 3.4.4 高效的内存队列,为了多线程操作变量时并发问题,用这个可以不用锁
> Netty 4.1.71.Final ws消息推送
# 其它

> `Generate MyPOJOs.groovy` 生成数据库Model
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.lmxdawn.dubboapi.req.ws;

import lombok.Data;

import java.io.Serializable;

/**
* ws 行情消息推送
*/
@Data
public class WsMarketDubboReq implements Serializable {

/**
* 委托单变化的用户ID
*/
private Long memberId;

/**
* 委托单变化的订单号
*/
private Long orderId;

/**
* 数据
*/
private String Data;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.lmxdawn.dubboapi.service.ws;

import com.lmxdawn.dubboapi.req.ws.WsMarketDubboReq;

/**
* ws 消息推送
*/
public interface WsPushDubboService {

/**
* 推送行情
*/
boolean market(WsMarketDubboReq req);

}
7 changes: 6 additions & 1 deletion gateway/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ spring.cloud.gateway.routes[4].filters[0]=StripPrefix=1
spring.cloud.gateway.routes[5].id=trade-route
spring.cloud.gateway.routes[5].uri=lb://service-trade
spring.cloud.gateway.routes[5].predicates[0]=Path=/trade/**
spring.cloud.gateway.routes[5].filters[0]=StripPrefix=1
spring.cloud.gateway.routes[5].filters[0]=StripPrefix=1

spring.cloud.gateway.routes[6].id=ws-route-route
spring.cloud.gateway.routes[6].uri=lb://service-ws-route
spring.cloud.gateway.routes[6].predicates[0]=Path=/ws-route/**
spring.cloud.gateway.routes[6].filters[0]=StripPrefix=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.lmxdawn.market.constant;

/**
* 消息队列主题常量
*/
public interface MqTopicConstant {

String WS_MARKET_TOPIC = "ws-market-topic";

}
33 changes: 33 additions & 0 deletions market/src/main/java/com/lmxdawn/market/mq/WsMarketMq.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.lmxdawn.market.mq;

import lombok.Data;

@Data
public class WsMarketMq {

/**
* 委托单变化的用户ID
*/
private Long memberId;

/**
* 委托单变化的订单号
*/
private Long orderId;

/**
* 对手委托单变化的用户ID
*/
private Long matchMemberId;

/**
* 对手委托单变化的订单号
*/
private Long matchOrderId;

/**
* 数据
*/
private String Data;

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.lmxdawn.market.stream;

import com.alibaba.fastjson.JSON;
import com.lmxdawn.dubboapi.req.match.MatchEventDubboReq;
import com.lmxdawn.dubboapi.service.match.MatchDubboService;
import com.lmxdawn.market.constant.CacheConstant;
import com.lmxdawn.market.constant.MqTopicConstant;
import com.lmxdawn.market.mq.EntrustOrderMq;
import com.lmxdawn.market.mq.WsMarketMq;
import com.lmxdawn.market.ws.DataVo;
import com.lmxdawn.market.ws.DepthVo;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
Expand All @@ -25,6 +30,9 @@ public class EntrustOrderStream {
@Autowired
private RedisTemplate<String, String> redisTemplate;

@Autowired
private StreamBridge streamBridge;

@DubboReference
private MatchDubboService matchDubboService;

Expand Down Expand Up @@ -74,9 +82,12 @@ public Consumer<EntrustOrderMq> entrustOrder() {

}

System.out.println(depthVoList);

DataVo dataVo = new DataVo();
dataVo.setDepthVoList(depthVoList);
WsMarketMq wsMarketMq = new WsMarketMq();
wsMarketMq.setData(JSON.toJSONString(dataVo));
// 推送 ws 深度行情
streamBridge.send(MqTopicConstant.WS_MARKET_TOPIC, wsMarketMq);

};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package com.lmxdawn.market.stream;

import com.alibaba.fastjson.JSON;
import com.lmxdawn.dubboapi.req.match.MatchEventDubboReq;
import com.lmxdawn.dubboapi.req.trade.EntrustOrderMatchDubboReq;
import com.lmxdawn.dubboapi.req.user.MemberCoinMatchDubboReq;
import com.lmxdawn.dubboapi.res.trade.EntrustOrderMatchDubboRes;
import com.lmxdawn.dubboapi.service.match.MatchDubboService;
import com.lmxdawn.dubboapi.service.trade.EntrustOrderDubboService;
import com.lmxdawn.market.constant.CacheConstant;
import com.lmxdawn.market.constant.MqTopicConstant;
import com.lmxdawn.market.mq.EntrustOrderMq;
import com.lmxdawn.market.mq.MatchDetailMq;
import com.lmxdawn.market.mq.WsMarketMq;
import com.lmxdawn.market.service.MatchService;
import com.lmxdawn.market.ws.DataVo;
import com.lmxdawn.market.ws.DepthVo;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
Expand All @@ -32,6 +37,9 @@ public class MatchDetailStream {
@Autowired
private RedisTemplate<String, String> redisTemplate;

@Autowired
private StreamBridge streamBridge;

@DubboReference
private EntrustOrderDubboService entrustOrderDubboService;

Expand Down Expand Up @@ -178,8 +186,16 @@ public Consumer<MatchDetailMq> matchDetail() {
}

// 推送 ws 深度行情
System.out.println(depthVoList);

DataVo dataVo = new DataVo();
dataVo.setDepthVoList(depthVoList);
WsMarketMq wsMarketMq = new WsMarketMq();
wsMarketMq.setMemberId(memberId);
wsMarketMq.setOrderId(id);
wsMarketMq.setMatchMemberId(matchMemberId);
wsMarketMq.setMatchOrderId(matchId);
wsMarketMq.setData(JSON.toJSONString(dataVo));
// 推送 ws 深度行情
streamBridge.send(MqTopicConstant.WS_MARKET_TOPIC, wsMarketMq);

};

Expand Down
14 changes: 14 additions & 0 deletions market/src/main/java/com/lmxdawn/market/ws/DataVo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lmxdawn.market.ws;

import lombok.Data;

import java.util.List;

@Data
public class DataVo {

private List<DepthVo> depthVoList;

private MatchVo matchVo;

}
17 changes: 17 additions & 0 deletions market/src/main/java/com/lmxdawn/market/ws/MatchVo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.lmxdawn.market.ws;

import lombok.Data;

@Data
public class MatchVo {

// 交易币种ID
private Long tradeCoinId;

// 计价币种ID
private Long coinId;

// 价格
private Double price;

}
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<module>market</module>
<module>trade</module>
<module>match</module>
<module>ws</module>
<module>ws-route</module>
</modules>
<name>parent</name>
<description>交易所项目</description>
Expand All @@ -42,6 +44,7 @@
<apache-commons.version>3.12.0</apache-commons.version>
<huaweicloud-obs.version>3.21.8</huaweicloud-obs.version>
<disruptor.version>3.4.4</disruptor.version>
<netty.version>4.1.71.Final</netty.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
</properties>

Expand Down Expand Up @@ -181,6 +184,13 @@
<version>${disruptor.version}</version>
</dependency>

<!--netty-->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>${netty.version}</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down
Loading

0 comments on commit 5a7d433

Please sign in to comment.