Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
nbcoolkid committed Dec 9, 2019
1 parent 0c0b0d1 commit e1a0be9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.zhangln.push.wspush;

import com.zhangln.push.wspush.config.prop.AppProp;
import com.zhangln.push.wspush.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
Expand All @@ -17,14 +19,17 @@
@Slf4j
public class NettyBooter implements ApplicationListener<ContextRefreshedEvent> {

@Autowired
private AppProp appProp;

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {

if (event.getApplicationContext().getParent() == null) {
//事件获得上下文对象化后启动服务器
try {
WebSocketServer.getInstance()
.start(10002);
.start(appProp.getWsPort());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void commomPush(Message message, Channel channel) {
HttpWsPushCondition httpWsPushCondition = (HttpWsPushCondition) o;
log.info("处理一次异步推送:{}", JSONObject.toJSONString(httpWsPushCondition));
HttpResVo httpResVo = wsPushService.commonPushService(httpWsPushCondition);
log.info("本次推送结果:{}",JSONObject.toJSONString(httpResVo));
// 广播本次推送结果
rabbitTemplate.convertAndSend("push-result", "", httpResVo);
} catch (Exception e) {
Expand Down Expand Up @@ -79,7 +80,7 @@ public void pushResult(Message message, Channel channel) {
ObjectInputStream oii = new ObjectInputStream(bais);) {
Object o = oii.readObject();
HttpResVo httpResVo = (HttpResVo) o;
log.info("接收到一次MQ异步推送结果:", JSONObject.toJSONString(httpResVo));
log.info("接收到一次MQ异步推送结果:{}", JSONObject.toJSONString(httpResVo));
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public void offLine(String channelId) {
List<LogWsConnectEntity> logWsConnectEntities = list.stream()
.map(logWsConnectEntity -> logWsConnectEntity.setStatus(3))
.collect(Collectors.toList());
iLogWsConnectService.updateBatchById(logWsConnectEntities);
if (!CollectionUtils.isEmpty(logWsConnectEntities)){
iLogWsConnectService.updateBatchById(logWsConnectEntities);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.zhangln.push.wspush.config.prop.AppProp;
import com.zhangln.push.wspush.entity.RegUserEntity;
import com.zhangln.push.wspush.service.IRegUserService;
import com.zhangln.push.wspush.vo.HttpWsPushCondition;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
Expand All @@ -22,6 +24,17 @@ class WsPushApplicationTests {
@Autowired
private AppProp appProp;

@Autowired
private RabbitTemplate rabbitTemplate;

@Test
public void testMqPush(){
HttpWsPushCondition httpWsPushCondition = new HttpWsPushCondition();
httpWsPushCondition.setContent("哇哈哈,我要推送啦");
httpWsPushCondition.setPushType("1");
rabbitTemplate.convertAndSend("push-common",httpWsPushCondition);
}

@Test
public void testAppProp(){
System.out.println(appProp.getActive());
Expand Down

0 comments on commit e1a0be9

Please sign in to comment.