import org.springframework.web.bind.annotation.RequestMapping;
10

10

11

12
/**
11
/**
13
 * @author huangbo
12
 * @author huangbo@asiainfo.com
13
 * @team IPU
14
 * @date 2017年11月26日 下午11:50:04
14
 * @date 2017年11月26日 下午11:50:04
15
 * @desc 
15
 * @desc 常用页面范例
16
 */
16
 */
17
@Controller
17
@Controller
18
@RequestMapping("/ui")
18
@RequestMapping("/ui")
19
public class UiController {
19
public class UiController {
20

20

21
	@RequestMapping("/login")
21
	@RequestMapping("/login")
22
    public String login() {
22
    public String pageLogin() {
23
        return "../login.html";
23
        return "../login.html";
24
    }
24
    }
25
	
25
	
31
		buff.append("/index.html");
31
		buff.append("/index.html");
32
		response.sendRedirect(buff.toString());
32
		response.sendRedirect(buff.toString());
33
	}
33
	}
34
	
35
	@RequestMapping("/404")
36
    public void page404(HttpServletRequest request, HttpServletResponse response) throws IOException  {
37
        StringBuilder buff = new StringBuilder();
38
        buff.append("../ipuui/");
39
        buff.append("demo");
40
        buff.append("/index.html");
41
        response.sendRedirect(buff.toString());
42
    }
43
	
44
	@RequestMapping("/error")
45
    public void pageError(HttpServletRequest request, HttpServletResponse response) throws IOException  {
46
        StringBuilder buff = new StringBuilder();
47
        buff.append("../ipuui/");
48
        buff.append("demo");
49
        buff.append("/index.html");
50
        response.sendRedirect(buff.toString());
51
    }
34
}
52
}

+ 40 - 0
ipu-rest-demo/src/main/java/com/ai/ipu/server/demo/dao/BizSqlDao.java

1
package com.ai.ipu.server.demo.dao;
2

3
import java.io.IOException;
4
import java.util.List;
5
import java.util.Map;
6

7
import com.ai.ipu.database.dao.impl.AbstractBizDao;
8

9
/**
10
 * @author huangbo@asiainfo.com
11
 * @team IPU
12
 * @date 2018年1月26日下午5:27:35
13
 * @desc 基于SQL的操作范例
14
 * 业务dao不暴露和业务无关的方法.
15
 */
16
public class BizSqlDao extends AbstractBizDao{
17

18
    public BizSqlDao(String connName) throws IOException {
19
        super(connName);
20
    }
21

22
    public List<Map<String, Object>> executeSql() throws Exception {
23
        String sql = "SELECT * FROM ipu_db_demo";
24
        List<Map<String, Object>> dataResult = getBasicDao().executeSelect(sql);
25
        return dataResult;
26
    }
27
    
28
    public int takePK() throws Exception {
29
        String sql = "SELECT * FROM ipu_db_demo order by datetime_type desc";
30
        Map<String, Object> dataResult = getBasicDao().executeSelectFirst(sql);
31
        int pk;
32
        if(dataResult==null||dataResult.isEmpty()){
33
            pk = 0;
34
        }else{
35
            pk = Integer.parseInt(dataResult.get("pk").toString());
36
            pk++;
37
        }
38
        return pk;
39
    }
40
}

+ 3 - 16
ipu-rest-demo/src/main/java/com/ai/ipu/server/demo/dao/DemoTableBizDao.java

10
 * @author huangbo@asiainfo.com
10
 * @author huangbo@asiainfo.com
11
 * @team IPU
11
 * @team IPU
12
 * @date 2018年9月6日下午10:05:42
12
 * @date 2018年9月6日下午10:05:42
13
 * @desc 单表增删改查测试
14
 * 建表语句
15
 CREATE TABLE `ipu_db_test` (
16
  `pk` varchar(20) CHARACTER SET utf8 NOT NULL COMMENT '键主',
17
  `string_type1` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT '字符串(可为空)',
18
  `string_type2` varchar(255) CHARACTER SET utf8 NOT NULL COMMENT '字符串(不为空)',
19
  `int_type1` int(11) DEFAULT NULL COMMENT '整型(可为空)',
20
  `int_type2` int(11) NOT NULL COMMENT '整型(不为空)',
21
  `date_type1` datetime DEFAULT NULL COMMENT '日期(不为空)',
22
  `date_type2` datetime NOT NULL COMMENT '日期(不为空)',
23
  `decimal_type1` decimal(10,0) DEFAULT NULL COMMENT '小数(可为空)',
24
  `decimal_type2` decimal(10,0) NOT NULL COMMENT '小数(不为空)',
25
  PRIMARY KEY (`pk`)
26
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
13
 * @desc 通用基于单表CRUD的操作范例
27
 */
14
 */
28
public class DemoTableBizDao extends AbstractBizDao{
15
public class CommonTableDao extends AbstractBizDao{
29

16

30
    public DemoTableBizDao(String connName) throws IOException {
17
    public CommonTableDao(String connName) throws IOException {
31
        super(connName);
18
        super(connName);
32
    }
19
    }
33

20


+ 0 - 40
ipu-rest-demo/src/main/java/com/ai/ipu/server/demo/dao/DemoBizDao.java

1
package com.ai.ipu.server.demo.dao;
2

3
import java.io.IOException;
4
import java.util.List;
5
import java.util.Map;
6

7
import com.ai.ipu.database.dao.impl.AbstractBizDao;
8

9
/**
10
 * @author huangbo@asiainfo.com
11
 * @team IPU
12
 * @date 2018年1月26日下午5:27:35
13
 * @desc 内置一个BasicDao,让业务dao不暴露和业务无关的方法.
14
 */
15
public class DemoBizDao extends AbstractBizDao{
16

17
    public DemoBizDao(String connName) throws IOException {
18
        super(connName);
19
    }
20

21
    public int insert() {
22
        return -1;
23
    }
24

25
    public int delete() {
26
        return -1;
27
    }
28

29
    public int update() throws Exception {
30
        String sql = "update TAB_IPU_MEMBER set PASSWORD='000002'";
31
        int result = dao.executeUpdate(sql, null);
32
        return result;
33
    }
34

35
    public List<Map<String, Object>> select() throws Exception {
36
        String sql = "SELECT * FROM tab_ipu_member";
37
        List<Map<String, Object>> dbResult = getBasicDao().executeSelect(sql);
38
        return dbResult;
39
    }
40
}

+ 0 - 42
ipu-rest-demo/src/main/java/com/ai/ipu/server/demo/dao/DemoDao.java

1
package com.ai.ipu.server.demo.dao;
2

3
import java.io.IOException;
4
import java.util.List;
5
import java.util.Map;
6

7
import com.ai.ipu.database.conn.SqlSessionManager;
8
import com.ai.ipu.database.dao.impl.BasicDao;
9
import com.ai.ipu.database.dao.impl.SqlDao;
10

11
/**
12
 * @author huangbo@asiainfo.com
13
 * @team IPU
14
 * @date 2018年1月26日下午5:27:43
15
 * @desc 继承BasicDao,让每个业务dao具备全量方法.
16
 */
17
public class DemoDao extends BasicDao {
18

19
    public DemoDao(String connName) throws IOException {
20
        super(connName);
21
    }
22

23
    public int insert() {
24
        return -1;
25
    }
26

27
    public int delete() {
28
        return -1;
29
    }
30

31
    public int update() throws Exception {
32
        String sql = "update TAB_IPU_MEMBER set PASSWORD='000002'";
33
        int result = executeUpdate(sql, null);
34
        return result;
35
    }
36

37
    public List<Map<String, Object>> select() throws Exception {
38
        String sql = "SELECT * FROM tab_ipu_member";
39
        List<Map<String, Object>> dbResult = executeSelect(sql);
40
        return dbResult;
41
    }
42
}

+ 1 - 1
ipu-rest-demo/src/main/resources/exception_messages_zh_CN.properties

1
100=条件参数不能为空
1
100=条件参数不能为空
2
200=[%v]不是主键,条件参数需要全部为主键
2
200=[%v]参数异常

+ 0 - 18
ipu-rest-demo/src/main/resources/ipu-spring-mvc.xml

11
		http://www.springframework.org/schema/mvc/spring-mvc.xsd">
11
		http://www.springframework.org/schema/mvc/spring-mvc.xsd">
12
	<!-- 自定义的control扫描目录 -->
12
	<!-- 自定义的control扫描目录 -->
13
    <context:component-scan base-package="com.ai.ipu.server.demo" />
13
    <context:component-scan base-package="com.ai.ipu.server.demo" />
14
    
15
    <!-- 定义文件上传解析器 -->
16
	<!-- <bean id="multipartResolver"
17
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
18
		设定默认编码
19
		<property name="defaultEncoding" value="UTF-8"></property>
20
		设定文件上传的最大值为5MB,5*1024*1024
21
		<property name="maxUploadSize" value="5242880"></property>
22
		设定文件上传时写入内存的最大值,如果小于这个参数不会生成临时文件,默认为10240
23
		<property name="maxInMemorySize" value="40960"></property>
24
		上传文件的临时路径
25
		<property name="uploadTempDir" value="fileUpload/temp"></property>
26
		延迟文件解析
27
		<property name="resolveLazily" value="true" />
28
	</bean> -->
29
    
30
    <!-- 不处理静态资源 -->
31
    <mvc:default-servlet-handler/>
32
</beans> 
14
</beans> 

+ 0 - 19
ipu-rest-demo/src/main/resources/ipu-spring-mvc2.xml

1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
5
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
6
           
7
    <!-- 处理器映射器 将bean的name作为url进行查找 -->
8
	<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
9
	<bean name="/name" class="com.ai.ipu.server.demo.control.BeanNameUrlController" />
10
	
11
	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
12
		<property name="mappings">
13
			<props>
14
				<prop key="/url">urlController</prop>
15
			</props>
16
		</property>
17
	</bean>
18
	<bean id="urlController" class="com.ai.ipu.server.demo.control.UrlController" />
19
</beans> 

msgframe的rocketmq测试代码 · 2876b3a8f4 - Nuosi Git Service
Browse Source

msgframe的rocketmq测试代码

liutong3 6 years ago
parent
commit
2876b3a8f4

+ 15 - 0
ipu-rocketmq-example/src/main/java/com/ai/ipu/example/rocketmq/RocketMQCustomer.java

1
package com.ai.ipu.example.rocketmq;
2
3
import com.ai.aif.msgframe.consumer.MfServiceStartup;
4
5
/**
6
 * @author liutong3
7
 * @team IPU
8
 * @date 2019/6/10 14:13
9
 * @desc 启动RocketMQ消费者
10
 */
11
public class RocketMQCustomer {
12
    public static void main(String[] args){
13
        MfServiceStartup.main();
14
    }
15
}

+ 23 - 0
ipu-rocketmq-example/src/main/java/com/ai/ipu/example/rocketmq/RocketMQCustomerExample.java

1
package com.ai.ipu.example.rocketmq;
2
3
import com.ai.aif.msgframe.common.IConsumerProcessor;
4
import com.ai.aif.msgframe.common.exception.ConsumerException;
5
import com.ai.aif.msgframe.common.message.MsgFMessage;
6
import com.ai.aif.msgframe.common.message.MsgFTextMessage;
7
8
/**
9
 * @author liutong3
10
 * @team IPU
11
 * @date 2019/6/10 14:15
12
 * @desc RocketMQ消费者
13
 */
14
public class RocketMQCustomerExample implements IConsumerProcessor {
15
    @SuppressWarnings("rawtypes")
16
    public Object process(MsgFMessage message) throws ConsumerException {
17
        if (message instanceof MsgFTextMessage) {
18
            System.out.println("{topic:" + message.getTopic() + ",value:" + ((MsgFTextMessage) message).getText() + "}");
19
        }
20
        return true;
21
    }
22
}
23

+ 114 - 0
ipu-rocketmq-example/src/main/java/com/ai/ipu/example/rocketmq/RocketMQProducerExample.java

1
package com.ai.ipu.example.rocketmq;
2
3
import com.ai.aif.msgframe.MfProducerClient;
4
import com.ai.aif.msgframe.common.CompletionListener;
5
import com.ai.aif.msgframe.common.message.MsgFMessage;
6
import com.ai.aif.msgframe.common.message.MsgFTextMessage;
7
import org.apache.log4j.Logger;
8
import org.junit.Test;
9
10
import java.util.Date;
11
12
/**
13
 * @author liutong3
14
 * @team IPU
15
 * @date 2019/6/10 14:16
16
 * @desc RocketMQ生产者
17
 */
18
public class RocketMQProducerExample {
19
    private static final Logger LOG = Logger.getLogger(RocketMQProducerExample.class);
20
    private final String TOPIC = "test";
21
    private final String MESSAGE = "test";
22
    private final String ORDERID = "1000";
23
24
    @Test
25
    public void testSendMessage() {
26
        String message = getMessage();
27
        sendMessage(TOPIC, message);
28
    }
29
30
    @Test
31
    public void testSendAsyncMessage() {
32
        String message = getMessage();
33
        sendAsyncMessage(TOPIC, message);
34
    }
35
36
    @Test
37
    public void testSendOrderMessage() {
38
        String message = getMessage();
39
        sendOrderMessage(TOPIC, message, ORDERID);
40
    }
41
42
    @Test
43
    public void testSendOneWay() {
44
        String message = getMessage();
45
        sendOneWay(TOPIC, message);
46
    }
47
48
    private String getMessage() {
49
        return MESSAGE + "_" + new Date().getTime();
50
    }
51
52
    private void sendMessage(String topic, String text) {
53
        try {
54
            MfProducerClient client = new MfProducerClient();
55
            MsgFTextMessage message = new MsgFTextMessage();
56
            message.setText(text);
57
            client.send(topic, message);
58
            LOG.debug("Sent:" + message);
59
            Thread.currentThread().sleep(1000);
60
        } catch (Exception e) {
61
            LOG.debug(e);
62
            throw new RuntimeException(e);
63
        }
64
    }
65
66
    private void sendAsyncMessage(String topic, final String text) {
67
        try {
68
            MfProducerClient client = new MfProducerClient();
69
            final MsgFTextMessage message = new MsgFTextMessage();
70
            message.setText(text);
71
            client.asyncSend(topic, message, new CompletionListener() {
72
                public void onCompletion(MsgFMessage msgFMessage) {
73
                    LOG.debug("Sent Success:" + msgFMessage.getMsgId() + "-" + text);
74
                }
75
76
                public void onException(MsgFMessage msgFMessage, Exception e) {
77
                    LOG.debug("Sent Error:" + msgFMessage.getMsgId() + "-" + text);
78
                }
79
            });
80
            Thread.currentThread().sleep(1000);
81
        } catch (Exception e) {
82
            LOG.debug(e);
83
            throw new RuntimeException(e);
84
        }
85
    }
86
87
    private void sendOrderMessage(String topic, final String text, String orderId) {
88
        try {
89
            MfProducerClient client = new MfProducerClient();
90
            final MsgFTextMessage message = new MsgFTextMessage();
91
            message.setText(text);
92
            client.sendOrderMsg(topic, message, orderId);
93
            LOG.debug("Sent:" + message);
94
            Thread.currentThread().sleep(1000);
95
        } catch (Exception e) {
96
            LOG.debug(e);
97
            throw new RuntimeException(e);
98
        }
99
    }
100
101
    private void sendOneWay(String topic, final String text) {
102
        try {
103
            MfProducerClient client = new MfProducerClient();
104
            final MsgFTextMessage message = new MsgFTextMessage();
105
            message.setText(text);
106
            client.sendOneway(topic, message);
107
            LOG.debug("Sent:" + message);
108
            Thread.currentThread().sleep(1000);
109
        } catch (Exception e) {
110
            LOG.debug(e);
111
            throw new RuntimeException(e);
112
        }
113
    }
114
}

+ 8 - 0
ipu-rocketmq-example/src/main/resources/log4j.properties

1
log4j.rootLogger=error, console
2
log4j.logger.org.apache.zookeeper=error
3
log4j.logger.com.ai.ipu.example=debug
4
5
log4j.appender.console=org.apache.log4j.ConsoleAppender
6
log4j.appender.console.target=System.out
7
log4j.appender.console.layout=org.apache.log4j.PatternLayout
8
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %5p [%t] (%F:%L) - %m%n

+ 22 - 0
ipu-rocketmq-example/src/main/resources/msgframe-config.xml

1
<?xml version="1.0" encoding="UTF-8"?>
2
<msgframeCfg xmlns="http://www.asiainfo.com/msgframe">
3
    <centerCfg>
4
        <name>ipu-rocketmq-example</name>
5
        <destinations>
6
            <queue name="test" belong="myCenter"/>
7
        </destinations>
8
        <subscribes>
9
            <subscribe subDestination="test">
10
                <implclass>com.ai.ipu.example.rocketmq.RocketMQCustomerExample</implclass>
11
            </subscribe>
12
        </subscribes>
13
        <centers>
14
            <center name="myCenter" containClusters="rocketmq-cluster"/>
15
        </centers>
16
        <clusters>
17
            <cluster name="rocketmq-cluster" type="RocketMQ">
18
                <url>47.105.160.21:9876</url>
19
            </cluster>
20
        </clusters>
21
    </centerCfg>
22
</msgframeCfg>