ENV:
采集:
文本索引创建:
BasicDBObject keys = new BasicDBObject();
keys.put("name","text");
BasicDBObject options = new BasicDBObject();
options.put("name", "userTextSearch");
options.put("unique", Boolean.FALSE);
options.put("background", Boolean.TRUE);
userCollection.createIndex(keys, options); // using MongoTemplate
Run Code Online (Sandbox Code Playgroud)
文献:
查询:
db.users.find( { "$text" : { "$search" : "LEONEL" } } ) =>找到了db.users.find( { "$text" : { "$search" : "leonel" } } ) => FOUND(搜索caseSensitive为false)db.users.find( { "$text" : { "$search" : "LEONÉL" } } ) => FOUND(使用diacriticSensitive搜索为false)db.users.find( { "$text" : { "$search" : "LEONE" } } …full-text-indexing mongodb mongodb-query aggregation-framework spring-data-mongodb
当前架构:
问题:
我们在前端和后端层之间有两步流程.
微服务2(MS2)需要验证来自前端的I1的完整性.如何避免对MS1的新查询?什么是最好的方法?
流程我正在尝试优化删除步骤1.3和2.3
流程1:
流程2:
途径
一种可能的方法是在MS2和MS1之间使用B2B HTTP请求,但我们将在第一步中复制验证.另一种方法是将数据从MS1复制到MS2.然而,由于数据量和它的波动性,这是令人望而却步的.复制似乎不是一个可行的选择.
我认为更合适的解决方案是前端有责任获取微服务2上的微服务1所需的所有信息并将其传递给微服务2.这将避免所有这些B2B HTTP请求.
问题是微服务1如何信任前端发送的信息.也许使用JWT以某种方式对来自微服务1的数据进行签名,并且微服务2将能够验证该消息.
注意 每次微服务2需要来自微服务1的信息时,执行B2B http请求.(HTTP请求使用ETAG和缓存控制:max-age).怎么避免这个?
建筑目标
微服务1需要来自微服务2的数据,以便能够在MS1数据库上保持MS1_Data和MS2_Data,因此使用代理的ASYNC方法不适用于此.
我的问题是,是否存在设计模式,最佳实践或框架,以实现这种推力沟通.
当前体系结构的缺点是在每个微服务之间执行的B2B HTTP请求的数量.即使我使用缓存控制机制,每个微服务的响应时间也会受到影响.每个微服务的响应时间至关重要.这里的目标是存档更好的性能,以及如何使用前端作为网关在多个微服务之间分配数据,但使用推力通信.
MS2_Data只是MS1必须用于维护数据完整性的产品SID或供应商SID的实体SID.
可能解决方案
这个想法是使用网关作为api网关请求处理,它将缓存来自MS1和MS2的一些HTTP响应,并将它们用作对MS2 SDK和MS1 SDK的响应.这样,在MS1和MS2之间不直接进行通信(SYNC或ASYNC),也避免了数据复制.
当然,上述解决方案仅适用于跨微服务的共享UUID/GUID.对于完整数据,事件总线用于以异步方式(事件源模式)跨微服务分发事件和数据.
灵感:https://aws.amazon.com/api-gateway/和https://getkong.org/
相关问题和文档:
architecture design-patterns data-sharing microservices aws-api-gateway
UT =单元测试IT =集成测试.我的所有Integration测试类都使用@Category(IntegrationTest.class)注释
我的目标是:
mvn clean install =>运行UT而不是IT
mvn clean install -DskipTests = true =>不执行任何测试
mvn clean deploy =>运行UT而不是IT
mvn clean test =>运行UT而不是IT
mvn clean verify =>运行UT和IT
mvn clean integration-test =>运行IT并且不执行UT
mvn clean install deploy =>运行UT而不是IT
pom属性:
<junit.version>4.12</junit.version>
<surefire-plugin.version>2.18.1</surefire-plugin.version>
<failsafe-plugin.version>2.18.1</failsafe-plugin.version>
Run Code Online (Sandbox Code Playgroud)
编译:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)单元测试:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<excludedGroups>com.xpto.IntegrationTest</excludedGroups>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)整合测试:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe-plugin.version}</version>
<configuration>
<groups>com.xpto.IntegrationTest</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
</configuration> …Run Code Online (Sandbox Code Playgroud)integration-testing maven maven-surefire-plugin maven-failsafe-plugin
我正在使用依赖:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我有以下对象:
public Class X {
private String a;
private String b;
private Y y;
}
public Class Y {
private String c;
private String d;
}
Run Code Online (Sandbox Code Playgroud)
我需要递归地记录类X的内容以获得类Y并使用JSON样式.这是我的目标,这就是这个问题的目的.
方法1:
ToStringStyle style = ToStringStyle.JSON_STYLE;
LOGGER.debug(ReflectionToStringBuilder.toString(new X(), style, false, false));
Run Code Online (Sandbox Code Playgroud)
方法1结果:
{"a":"<a>","b":"<b>","y": com.<packages>.y@<hash>}
Run Code Online (Sandbox Code Playgroud)
方法2:
RecursiveToStringStyle style = new RecursiveToStringStyle();
LOGGER.debug(ReflectionToStringBuilder.toString(new X(), style, false, false));
Run Code Online (Sandbox Code Playgroud)
方法2结果:
[com.<packages>.x@<hash>[a=<a>,b=<b>,y=com.<packages>.y@<hash>[c=<c>,d=<d>]]
Run Code Online (Sandbox Code Playgroud)
成功的方法:
`Merge of Approach 1 and Approach 2` but how to achieve this?
Run Code Online (Sandbox Code Playgroud)
成功的方法结果(我的目标):
{"a":"<a>","b":"<b>","y":{"c":"<c>","d":"<d>"}}
Run Code Online (Sandbox Code Playgroud) Maven版本:3.3.3.Findbugs插件版本:3.0.1
我正在使用findbugs-maven-plugin,我需要在src和测试类上运行findbugs插件.目前,它仅适用于源类
Target
|_ classes
|_ test-classes
|_ findbugs (only have results regarding classes folder)
Run Code Online (Sandbox Code Playgroud)我需要为PMD插件做同样的事情.同样的提示可能吗?
相关问题:
Findbugs maven配置:
<profile>
<id>findbugs</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs.version}</version>
<configuration>
<effort>Max</effort>
<failOnError>true</failOnError>
<threshold>Low</threshold>
<xmlOutput>true</xmlOutput>
<includeTests>true</includeTests>
<excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
</configuration>
<executions>
<execution>
<id>analyze-compile</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
<goal>findbugs</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud) 我正在使用春季启动项目.
环境:
ch.qos.logback:logback-core:jar:1.1.5
ch.qos.logback:logback-classic:jar:1.1.5
org.springframework.boot:spring-boot-starter-logging:jar:1.3.3.RELEASE
Run Code Online (Sandbox Code Playgroud)
在我的项目中,我正在使用application.yml的属性(application-dev.yml和application-production.yml)
由于Logback Spring扩展在Spring之前启动,因此我无法将spring.profiles.active注入到logback.xml文件中.
这是我的logback.xml文件的更简单版本:
<configuration scan="true">
<property name="LOG_PATH" value="/var/log/" />
<property name="APP_NAME" value="xyz" />
<property name="PROFILE" value="-${spring.profiles.active}" />
<property name="CHARSET" value="utf-8" />
<property name="PATTERN" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
<appender name="APP-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}${APP_NAME}${PROFILE}.log</file>
<encoder>
<charset>${CHARSET}</charset>
<Pattern>${PATTERN}</Pattern>
</encoder>
</appender>
<logger name="a.b.c" level="INFO">
<appender-ref ref="APP-FILE" />
</logger>
<root level="INFO">
<appender-ref ref="APP-FILE"/>
</root>
Run Code Online (Sandbox Code Playgroud)
我正在寻找的PROFILE是属性spring.profiles.active.
我的目标是在目录/ var/log上有一个日志文件,文件xyz-dev或xyz-production,但我得到的是xyz-spring.profiles.active_IS_UNDEFINED.log.
处理办法:
1 - 使用如下组件:
@Component
public class InitializationService implements ApplicationListener<ContextRefreshedEvent> …Run Code Online (Sandbox Code Playgroud) 环境:
spring-data-mongo:1.7.0.RC1
mongo-java-driver:3.2.2
文献:
@Document(collection = "products")
public class Product {
@Id
private String sid;
private String name;
private Long vendor;
(...)
}
Run Code Online (Sandbox Code Playgroud)
库:
public interface ProductRepository extends MongoRepository<Product, String> {
Product findByName(String productName);
}
Run Code Online (Sandbox Code Playgroud)
我的目标是拦截对Product集合执行的任何查询,并添加谓词或规范,而无需修改存储库或需要实现方法findByNameAndBelongsToVendorList.
我需要这个拦截器或aspectJ,因为我有多个方法,如:
Page<Product> findAll(Pageable page);
List<Product> findByCategory(String category, Pageable pageRequest);
(...)
Run Code Online (Sandbox Code Playgroud)
目标
findByName // perform a filter by name (explicit)
// and a filter by vendor (injected via inteceptor or aspecJ)
Run Code Online (Sandbox Code Playgroud)
避免这样做
@Repository
public class ProductRepositoryCustomImpl implements ProductRepositoryCustom {
@Autowired
private MongoTemplate template; …Run Code Online (Sandbox Code Playgroud) 我正在使用查询dsl和spring数据.
环境:
<querydsl-apt.version>4.1.4</querydsl-apt.version>
<querydsl-jpa.version>4.1.4</querydsl-jpa.version>
<querydsl-sql.version>4.1.4</querydsl-sql.version>
<spring>4.3.3.RELEASE</spring>
Run Code Online (Sandbox Code Playgroud)
查询:
JPAQueryFactory query = new JPAQueryFactory(getEntityManager());
SimpleExpression<Long> rowNumber = SQLExpressions.rowNumber()
.over()
.orderBy(qServiceExecution.updatedAt.asc()).as("rowNumber");
List<Tuple> response = query.select(qServiceExecution.id, SQLExpressions.rowNumber()
.over()
.orderBy(qServiceExecution.updatedAt.asc()))
.from(qServiceExecution)
.fetch();
Run Code Online (Sandbox Code Playgroud)
例外:
Root cause: java.lang.IllegalArgumentException: No pattern found for ROWNUMBER
at com.querydsl.core.support.SerializerBase.visitOperation(SerializerBase.java:280) ~[querydsl-core-4.1.4.jar:na]
at com.querydsl.jpa.JPQLSerializer.visitOperation(JPQLSerializer.java:437) ~[querydsl-jpa-4.1.4.jar:na]
at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:231) ~[querydsl-core-4.1.4.jar:na]
at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:31) ~[querydsl-core-4.1.4.jar:na]
Spring error: No pattern found for ROWNUMBER; nested exception is java.lang.IllegalArgumentException: No pattern found for ROWNUMBER
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:384) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:246) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:491) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
Run Code Online (Sandbox Code Playgroud)
查询DSL文档: …
java ×5
maven ×2
mongodb ×2
spring ×2
spring-data ×2
architecture ×1
data-sharing ×1
findbugs ×1
hibernate ×1
logback ×1
querydsl ×1
reflection ×1
row-number ×1
spring-boot ×1
tostring ×1