我在尝试创建Spring Data Mongo存储库时遇到问题.
相关代码和配置:-
模特班: -
@Document(collection = "USER_DETAIL")
public class UserDetail implements
org.springframework.security.core.userdetails.UserDetails, Serializable {
private static final long serialVersionUID = -2637223077307659181L;
@Id
private String id;
@Indexed(dropDups = true, name = "usernameIndex", unique = true)
private String username;
private String fname;
private String lname;
private List<UserRole> authorities;
private String password;
private boolean accountNonExpired;
private boolean accountNonLocked;
private boolean credentialsNonExpired;
private boolean enabled;
// getter & setters.
}
Run Code Online (Sandbox Code Playgroud)
Spring Data Repository类: -
public interface UserDetailsRepository extends
MongoRepository<UserDetail, String> {
/** …Run Code Online (Sandbox Code Playgroud) 我已经在本地启动了 Kafka 代理实例,并使用 jmx_prometheus_javaagent 作为 java 代理。
我对给定主题的当前消息传入率感兴趣,并在 Grafana 仪表板中呈现相同的消息率。在 jconsole 中探索 MBean,我可以看到有一个名为kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec,topic=ABCD以 MeanRate、OneMinuteRate、Count 等属性命名的对象,这似乎符合我的目的:-
为了尝试我的设置,我使用一个简单的 KafkaProducer 向本地 kafka 代理发送非常小的消息,该消息能够在不到 5 秒的时间内发送 100 万条消息,然后停止。对于这个实验,我预计在这 5 秒内会看到 MeanRate 出现峰值,然后又回到 0。
问题
即使没有消息传入(生产者已停止),在生产者停止发送消息很久之后,我也会看到 MeanRate 的值不为零:-

同样在普罗米修斯图中反映为:-
普罗米修斯配置:-
- pattern : kafka.server<type=(.+), name=(.+)PerSec\w*, topic=(.+)><>MeanRate
name: kafka_server_$1_$2_mean_rate
labels:
topic: "$3"
Run Code Online (Sandbox Code Playgroud)
普罗米修斯查询 -floor(kafka_server_brokertopicmetrics_messagesin_mean_rate)
获得准确的消息传入率的正确方法/prometheus-query/mbean 是什么?
考虑一个简单的类: -
class Person{
String name
String email
int age
String mobileNum
}
Run Code Online (Sandbox Code Playgroud)
我想有选择地将'id'和'email'属性作为JSON响应发送.使用时: -
return theObject as JSON
Run Code Online (Sandbox Code Playgroud)
响应具有所有属性:值对.
我正在使用Spring Data Mongo存储库来保存我的实体.所有实体的父类如下所示: -
@Document
public abstract class AbstractEntity {
@Id
private String id;
@CreatedDate
private Date dateCreated;
@LastModifiedDate
private Date lastUpdated;
@Version
private Long version; // This is creating trouble while 'update' operation
}
Run Code Online (Sandbox Code Playgroud)
这是我配置Mongo存储库和审计的方式: -
@Configuration
@EnableMongoRepositories(basePackages = { "x.y.z" })
@EnableMongoAuditing
@EnableAutoConfiguration
public class MongoRepositoryConfig {
}
Run Code Online (Sandbox Code Playgroud)
我能够将我的实体保存并"更新"到Mongo,直到我不在我的实体中包含@Version字段进行审核.
如果我在我的实体类中使用@Version审计字段,在尝试使用MongoRepository#save(entity)方法更新实体/文档时,我会遇到以下异常: -
Caused by: com.mongodb.MongoException$DuplicateKey: { "serverUsed" : "localhost:27017" , "ok" : 1 , "n" : 0 , "err" : "insertDocument :: caused by :: 11000 E11000 duplicate …Run Code Online (Sandbox Code Playgroud) 我有一个域类(缩小)为: -
class Expense {
Date dateOfExpense
int amount
}
Run Code Online (Sandbox Code Playgroud)
我试图获得按周/月/费用日期分组的金额总和.参考grails doc http://grails.org/doc/latest/guide/GORM.html中的 'sqlGroupProjection'方法,
我尝试使用以下代码: -
def results = c {
between("dateOfExpense", fromDate, toDate)
projections {
sqlGroupProjection 'dateOfExpense,sum(amount) as summed',
'MONTH(dateOfExpense)',['date','summed'],[DATE,NUMBER]
}
}
Run Code Online (Sandbox Code Playgroud)
抛出异常:
No such property: DATE for class: grails.orm.HibernateCriteriaBuilder. Stacktrace follows:
Message: No such property: DATE for class: grails.orm.HibernateCriteriaBuilder
Run Code Online (Sandbox Code Playgroud)
请建议使用sqlGroupProjection方法的方法
如何配置Spring Boot以在443处使用HTTPS端口运行Jetty.配置还应注意生成密钥.
简而言之,以下maven插件的等效配置,: -
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>generate-resources</phase>
<id>clean</id>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<phase>generate-resources</phase>
<id>genkey</id>
<goals>
<goal>generateKeyPair</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
<dname>cn=my.hostname.tld</dname>
<!-- put your CN here -->
<keypass>jetty6</keypass>
<storepass>jetty6</storepass>
<alias>jetty6</alias>
<keyalg>RSA</keyalg>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
和:-
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<jvmArgs>-Xmx2048m -Xms1536m -XX:PermSize=128m -XX:MaxPermSize=256m</jvmArgs>
<!-- http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin -->
<scanIntervalSeconds>10</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9999</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
<connector implementation="org.mortbay.jetty.security.SslSocketConnector">
<port>9993</port>
<maxIdleTime>60000</maxIdleTime>
<keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
<password>jetty6</password>
<keyPassword>jetty6</keyPassword>
</connector>
</connectors>
<contextPath>/</contextPath>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) grails ×2
java ×2
mongodb ×2
apache-kafka ×1
converters ×1
grails-orm ×1
jmx ×1
json ×1
prometheus ×1
spring-boot ×1