前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >一个综合的分布式项目之项目环境准备 原

一个综合的分布式项目之项目环境准备 原

作者头像
尚浩宇
发布2018-08-17 10:30:00
5420
发布2018-08-17 10:30:00
举报
文章被收录于专栏:杂烩

    统一JDK为1.7

    tomcat端口上下游各为8080和8088,其他服务端口默认

    开发工具eclipse

    版本控制git(为方便公网查看,初期会托管到github)

    其他各项服务暂时不用启动,先创建项目。

    创建maven项目相信看到这的oscer都会,这里就不赘述,主要贴出一些配置文件(限于篇幅随意贴了点,全部的请看github上)。

github地址:https://github.com/shang7053/base/tree/master/sustainable-parent

同时导入一份到osc-git,地址:http://git.oschina.net/loveliyiyi/base

    这篇博客改了好多次,最终还是决定不贴上配置信息,因为一方面占用篇幅太大,还有一方面他在博客里并没有太多意义,只有用到的时候再贴就好了。

    基本环境如上所述,现在用文字说明一下各项目之间的关系。

    首先是parent项目,这个项目集成了一些基本的依赖,比如spring相关、MQ、junit等等,是公共的依赖。

    然后是sustainable-interactive,这个项目集成了redis以及springmvc等依赖。

    最后是sustainable-service,这个就多了,有mybatis的、有mongo的等等。

    至于common的包基本上也就放点工具包,服务接口之类的,可能会用到比如gson的第三方工具,倒没什么可说的。

    还有一个就是各种配置文件,大部分集成到spring,小部分是基于以前自己写的工具包,比如redis,因为为了方便切换缓存,搞了一个公共的缓存接口,然后自己用oscache或者ehcache或者redis实现,所以这里就直接拿来用了。

    最后就是页面了,登陆注册也没啥,最原生态的标签,所以页面看着……基本能用吧,就不献丑了。

    贴一下spring的配置文件吧,看这个估计就差不多了。

sustainable-interactive

代码语言:javascript
复制
context:annotation-config />
	<context:component-scan base-package="sustainable.interactive" />
	<tx:annotation-driven/>
	<import resource="dubbo-customer.xml"/>
	<context:property-placeholder location="classpath:redis.properties" />  
  
    <import resource="mq.xml"/>

dubbo-customer.xml

代码语言:javascript
复制
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
	<dubbo:application name="dubbo_consumer" />

	<!-- 使用zookeeper注册中心暴露服务地址 -->
	<dubbo:registry address="zookeeper://zookeeper.sustainable.com:2181" />

	<!-- 生成远程服务代理,可以像使用本地bean一样使用demoService		xml配置时使用
	<dubbo:reference id="userDao" interface="scc.common.user.IUserDao" /> -->
	<!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 -->
	<dubbo:annotation package="sustainable.interactive" />

mq.xml

代码语言:javascript
复制
<!-- 基本配置开始 -->
    <!-- 连接工厂 -->
	<bean id="connectinFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
		<!-- 配置连接 -->
		<property name="brokerURL" value="tcp://activeMq.sustainable.com:61616" />
	</bean>
	<!-- spring管理连接的工厂 -->
	<bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
		<!-- 目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory -->
		<property name="targetConnectionFactory" ref="connectinFactory"></property>
		<!-- Session缓存数量 -->
		<property name="sessionCacheSize" value="10"></property>
	</bean>
	<!-- Spring JMS Template 配置JMS模版 -->
	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory" ref="cachingConnectionFactory" />
	</bean>
	<!-- 注册消息转换器 -->
	<bean id="messageConverter" class="sustainable.common.util.jms.SustainableMessageConverter"/>
	<!-- 基本配置结束 -->
	
	<!-- 注册队列开始 -->
	<!-- 注册Queue队列:仅有一个订阅者会收到消息,消息一旦被处理就不会存在队列中 -->
	<bean id="registQueue" class="org.apache.activemq.command.ActiveMQQueue">
		<!-- 队列名称 -->
		<constructor-arg value="regist.notify"></constructor-arg>
	</bean>
	<!-- 使用Spring JmsTemplate 的消息生产者 -->
	<bean id="registQueueMessageProducer" class="sustainable.common.util.jms.QueueMessageProducer">
		<property name="jmsTemplate" ref="jmsTemplate"></property>
		<property name="queue" ref="registQueue"></property>
		<property name="messageConverter" ref="messageConverter"></property>
	</bean>
	<!-- 注册队列结束 -->

sustainable-service

代码语言:javascript
复制
<context:annotation-config />
	<context:component-scan base-package="sustainable.service" />
	<!-- 数据源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="driverClass" value="com.mysql.jdbc.Driver" />
		<property name="jdbcUrl" value="jdbc:mysql://mysql.sustainable.com:3306/test" />
		<property name="user" value="root" />
		<property name="password" value="1234" />
		<!--连接池中保留的最小连接数。 -->
		<property name="minPoolSize" value="1" />
		<!--连接池中保留的最大连接数。Default: 15 -->
		<property name="maxPoolSize" value="5" />
		<!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
		<property name="initialPoolSize" value="3" />
		<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
		<property name="maxIdleTime" value="60" />
		<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
		<property name="acquireIncrement" value="5" />
		<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。 如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 
			0 -->
		<property name="maxStatements" value="0" />
		<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
		<property name="idleConnectionTestPeriod" value="60" />
		<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
		<property name="acquireRetryAttempts" value="30" />
		<!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试 获取连接失败后该数据源将申明已断开并永久关闭。Default: 
			false -->
		<property name="breakAfterAcquireFailure" value="true" />
		<!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable 等方法来提升连接测试的性能。Default: 
			false -->
		<property name="testConnectionOnCheckout" value="false" />
	</bean>
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- mapper.xml文件对应的接口 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="sustainable.service.dao" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
	</bean>
	<!-- 注解事物 -->
	<tx:annotation-driven />
	<aop:aspectj-autoproxy />
	<import resource="dubbo_provider.xml" />
	<import resource="mq.xml" />
	<import resource="mongo-config.xml"/>

dubbo_provider.xml

代码语言:javascript
复制
<!-- 提供方应用信息,用于计算依赖关系 -->
	<dubbo:application name="dubbo_provider" />

	<!-- 使用zookeeper注册中心暴露服务地址 -->
	<dubbo:registry address="zookeeper://zookeeper.sustainable.com:2181" />

	<!-- 用dubbo协议在20880端口暴露服务 -->
	<dubbo:protocol name="dubbo" port="20880" />

	<!-- 声明需要暴露的服务接口 		xml式配置
	<dubbo:service interface="scc.common.user.IUserDao" ref="userDaoImpl" />-->
	<!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 -->
	<dubbo:annotation package="sustainable.service.service" />

mq.xml

代码语言:javascript
复制
<!-- 基本配置开始 -->
	<!-- ActiveMQ 连接工厂 -->
	<bean id="connectinFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
		<property name="brokerURL" value="tcp://activeMq.sustainable.com:61616" />
	</bean>
	<!-- Spring用于管理真正的ConnectionFactory的ConnectionFactory -->
	<bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
		<!-- 目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory -->
		<property name="targetConnectionFactory" ref="connectinFactory"></property>
		<!-- Session缓存数量 -->
		<property name="sessionCacheSize" value="10"></property>
	</bean>
	<!-- Spring JMS Template 配置JMS模版 -->
	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory" ref="cachingConnectionFactory" />
	</bean>
	<!-- 注册消息转换器 -->
	<bean id="messageConverter" class="sustainable.common.util.jms.SustainableMessageConverter"/>
	<!-- 基本配置结束 -->
	
	<!-- 注册队列开始 -->
	<!-- 注册Queue队列:仅有一个订阅者会收到消息,消息一旦被处理就不会存在队列中 -->
	<bean id="registQueue" class="org.apache.activemq.command.ActiveMQQueue">
		<!-- 队列名称 -->
		<constructor-arg value="regist.notify"></constructor-arg>
	</bean>
	<!-- 消息处理 -->
	<bean id="registDealJmsMessage" class="sustainable.service.jms.RegistDeal"/>
	<!-- 异步接收消息处理类 -->
	<bean id="registQueueMessageListener" class="sustainable.common.util.jms.QueueMessageListener">
		<property name="dealJmsMessage" ref="registDealJmsMessage"></property>
	</bean>
	<!-- 消息监听容器 -->
	<bean id="registQueueContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
		<property name="connectionFactory" ref="connectinFactory"></property>
		<property name="destination" ref="registQueue"></property>
		<property name="messageListener" ref="registQueueMessageListener"></property>
	</bean>
	<!-- 注册队列结束 -->
	
	<!-- 同步user队列开始 -->
	<!-- 注册Queue队列:仅有一个订阅者会收到消息,消息一旦被处理就不会存在队列中 -->
	<bean id="syncUserQueue" class="org.apache.activemq.command.ActiveMQQueue">
		<!-- 队列名称 -->
		<constructor-arg value="syncUser.notify"></constructor-arg>
	</bean>
	<!-- 使用Spring JmsTemplate 的消息生产者 -->
	<bean id="syncUserQueueMessageProducer" class="sustainable.common.util.jms.QueueMessageProducer">
		<property name="jmsTemplate" ref="jmsTemplate"></property>
		<property name="queue" ref="syncUserQueue"></property>
		<property name="messageConverter" ref="messageConverter"></property>
	</bean>
	<!-- 同步user队列结束 -->
	
	<!-- 同步user队列开始 -->
	<!-- 消息处理 -->
	<bean id="syncUserDealJmsMessage" class="sustainable.service.jms.SyncUserDealJmsMessage"/>
	<!-- 异步接收消息处理类 -->
	<bean id="syncUserQueueMessageListener" class="sustainable.common.util.jms.QueueMessageListener">
		<property name="dealJmsMessage" ref="syncUserDealJmsMessage"></property>
	</bean>
	<!-- 消息监听容器 -->
	<bean id="syncUserQueueContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
		<property name="connectionFactory" ref="connectinFactory"></property>
		<property name="destination" ref="syncUserQueue"></property>
		<property name="messageListener" ref="syncUserQueueMessageListener"></property>
	</bean>
	<!-- 同步user队列结束 -->

mongo-config.xml

代码语言:javascript
复制
<!-- Default bean name is 'mongo' -->
	<mongo:mongo host="mongo.sustainable.com" port="27017" />
	<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
		<constructor-arg ref="mongo" />
		<constructor-arg name="databaseName" value="test" />
	</bean>

页面还是上个图好了

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016/01/22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档