Skip to content

Commit

Permalink
将listener移动到各个rpc框架下
Browse files Browse the repository at this point in the history
  • Loading branch information
xlorne committed Dec 20, 2017
1 parent 1d49a44 commit f9dca4e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
</execution>
</executions>
</plugin>
<!-- 手动打包时,将下面的plugin注释掉 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.codingapi.tx.listener;
package com.codingapi.tx.dubbo.listener;

import com.codingapi.tx.listener.service.InitService;
import org.springframework.beans.BeansException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.codingapi.tx.motan.listener;

import com.codingapi.tx.listener.service.InitService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
* Created by lorne on 2017/7/1.
*/
@Component
public class TransactionSocketListener implements ApplicationContextAware {


@Autowired
private InitService initService;


@Override
public void setApplicationContext(ApplicationContext event) throws BeansException {
initService.start();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.codingapi.tx.springcloud.listener;

import com.codingapi.tx.listener.service.InitService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
Expand All @@ -8,11 +12,19 @@
@Component
public class ServerListener implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {

private Logger logger = LoggerFactory.getLogger(ServerListener.class);

private int serverPort;

@Autowired
private InitService initService;

@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
logger.info("onApplicationEvent -> onApplicationEvent. "+event.getEmbeddedServletContainer());
this.serverPort = event.getEmbeddedServletContainer().getPort();

initService.start();
}

public int getPort() {
Expand Down
5 changes: 0 additions & 5 deletions tx-client/src/main/java/com/codingapi/tx/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,5 @@ public class Constants {
*/
public static int maxOutTime = 10000;

/**
* 模块唯一标示
*/
public static String uniqueKey;


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.codingapi.tx.listener.service.impl;

import com.codingapi.tx.Constants;
import com.codingapi.tx.listener.service.InitService;
import com.codingapi.tx.listener.service.ModelNameService;
import com.codingapi.tx.netty.service.NettyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -20,20 +18,9 @@ public class InitServiceImpl implements InitService {
@Autowired
private NettyService nettyService;


@Autowired
private ModelNameService modelNameService;


@Override
public void start() {

/**
* 设置模块唯一标示
*/

Constants.uniqueKey = modelNameService.getUniqueKey();

nettyService.start();
logger.info("socket-start..");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private boolean isIp(String ipAddress) {
public List<InstanceInfo> getConfigServiceInstances() {
Application application = eurekaClient.getApplication(tmKey);
if (application == null) {
logger.error("获取eureka服务失败!");
logger.error("get eureka server error!");
}
return application != null ? application.getInstances() : new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TxCoreServerHandler(NettyService nettyService) {
@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
final String json = SocketUtils.getJson(msg);
logger.info("接受->"+json);
logger.info("request->"+json);
threadPool.execute(new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit f9dca4e

Please sign in to comment.