我们使用 Spring AMQP 从 RabbitMQ 读取消息,现在我们一次只能从队列中读取一条消息,我是否可以从队列中读取多条消息然后处理批处理?
我看到 Spring 中有一个 BatchingStrategy 可用,我如何将其插入到 connectionFactory 中?
这是我的代码:
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
JsonMessageConverter converter = new JsonMessageConverter();
DefaultClassMapper defaultClassMapper = new DefaultClassMapper();
defaultClassMapper.setDefaultType(Message.class);
converter.setClassMapper(defaultClassMapper);
factory.setMessageConverter(converter);
factory.setConcurrentConsumers(3);
Run Code Online (Sandbox Code Playgroud)
...
public class Processor implements IChannelProcessor {
@Override
public void process(Message message) {
validateMessageEvent(message);
// process the message
Run Code Online (Sandbox Code Playgroud) 我是 Spock 的新手,试图编写一个简单的 Spock 但它失败了:
Error:Groovyc: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:.../.m2/repository/org/spockframework/spock-core/1.0-groovy-2.4/spock-core-1.0-groovy-2.4.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
这是我的规格:
@Unroll
class UserFilterSpec extends Specification {
private static final String USER_ID_1 = "someUserId1";
private static final String USER_ID_2 = "someUserId2";
private static final String USER_ID_3 = "someUserId3";
def filter = new UserFilter()
def User user1 = setupTestUser(USER_ID_1)
def User user2 = setupTestUser(USER_ID_2)
def User user3 = setupTestUser(USER_ID_3)
def "given a list of users and list of user ids, should …Run Code Online (Sandbox Code Playgroud) 我有一个猪脚本,需要从本地 hadoop 集群加载文件。我可以使用 hadoop 命令列出文件:hadoop fs –ls /repo/mydata,` 但是当我尝试在 pig 脚本中加载文件时,它失败了。加载语句是这样的:
in = LOAD '/repo/mydata/2012/02' USING PigStorage() AS (event:chararray, user:chararray)
Run Code Online (Sandbox Code Playgroud)
错误信息是:
Message: org.apache.pig.backend.executionengine.ExecException: ERROR 2118: Input path does not exist: file:/repo/mydata/2012/02
Run Code Online (Sandbox Code Playgroud)
任何的想法?谢谢
我正在使用大量的Java存储UUID到HashMap一行UUID.toString().由于数据量巨大,很快就会抛出OutOfMemoryError.现在我正在考虑一种紧凑的方式来表示UUID,最好是类似的东西long,然后我可以轻松地UUID用该long表示重建.这可能吗?
我在META-INF /文件夹中有一个persistence.xml:
<persistence-unit name="dev" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/events" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
在java代码中,我从该persistence.xml创建实体管理器facotry
_emf = Persistence.createEntityManagerFactory("dev");
_em = _emf.createEntityManager();
Run Code Online (Sandbox Code Playgroud)
但是我想要动态更改jdbc url/user/password进行测试,我的计划是将这些参数保存在配置文件中并根据需要读取它们,所以有一种方法可以在我从持久性创建entitymanagerfactory后更新它们. XML?所以它想这样:
_emf = Persistence.createEntityManagerFactory("dev");
_emf.setProperties("url", "test_url");
... other setts here ...
_em = _emf.createEntityManager();
Run Code Online (Sandbox Code Playgroud)
谢谢
我有 DataDram 看起来像这样:
+-------+---------+
|email |timestamp|
+-------+---------+
|x@y.com| 1|
|y@m.net| 2|
|z@c.org| 3|
|x@y.com| 4|
|y@m.net| 5|
| .. | ..|
+-------+---------+
Run Code Online (Sandbox Code Playgroud)
对于每封电子邮件,我都想保留最新记录,因此结果将是:
+-------+---------+
|email |timestamp|
+-------+---------+
|x@y.com| 4|
|y@m.net| 5|
|z@c.org| 3|
| .. | ..|
+-------+---------+
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?我是火花和数据框的新手。
我在 maven build 中添加了 checkstyle 但由于某种原因它只检查 src/main 文件夹并忽略 src/test 文件夹,这是我的项目结构:
Proj
- Module A
- src
- main
- java
- resources
- test
- java
- resources
- Module B
- src
- main
- java
- resources
- test
- java
- resources
pom.xml
checkstyle.xml
Run Code Online (Sandbox Code Playgroud)
和我的 pom.xml
<properties>
<checkstyle.version>3.0.0</checkstyle.version>
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
<checkstyle.consoleOutput>true</checkstyle.consoleOutput>
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
<encoding>UTF-8</encoding>
</properties>
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.18</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<testSourceDirectories>src/test/java</testSourceDirectories>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals> …Run Code Online (Sandbox Code Playgroud) 我有一个从数据库检索数据并返回Future [ResponseDTO]类型的函数,然后我需要将其转换为HttpResponse的Future
我的代码:
val responseDTO = database.getResponseDto(service) => Future[ResponseDTO]
responseDTO.onComplete {
case Success(responseDTO) => HttpResponse(status = responseDTO.responseCode, entity = responseDTO.responsePayload)
case Failure(exception) => HttpError("error")
}
Run Code Online (Sandbox Code Playgroud)
它不会工作
也尝试过这个,仍然不起作用
responseDTO.map(
dto => EitherT.pure[Future, HttpError](HttpResponse(status = dto.responseCode, entity = dto.responsePayload))
)
Run Code Online (Sandbox Code Playgroud) 我正在遵循 quarkus 入门教程,能够生成可执行文件并运行它,但无法运行 docker 映像。
脚步:
./mvnw package -Pnative (有效)
docker build -f src/main/docker/Dockerfile.native -t quarkus/getting-started 。(有效
docker run -i --rm -p 8080:8080 quarkus/getting-started,出现此错误:
standard_init_linux.go:228: exec 用户进程导致: exec 格式错误
我的设置: Quarkus 版本:2.7.2.final macOS Catalina 版本 10.15.7 Java 版本:
openjdk version "11.0.14" 2022-01-18
OpenJDK Runtime Environment GraalVM CE 22.0.0.2 (build 11.0.14+9-jvmci-22.0-b05)
OpenJDK 64-Bit Server VM GraalVM CE 22.0.0.2 (build 11.0.14+9-jvmci-22.0-b05, mixed mode, sharing)
Run Code Online (Sandbox Code Playgroud)
Maven版本:3.8.3
请帮忙
我们需要构造一个包含很多条件的 Mysql 查询:
where userId=useIdi1 or userId=userId2 or userId=userId3....
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用 IN 代替,但只是好奇我们可以传递给 MySQL 中的 WHERE 子句的参数(参数)数量是否有限制?
java ×2
apache-pig ×1
groovy ×1
hadoop ×1
hibernate ×1
jpa ×1
maven ×1
mysql ×1
quarkus ×1
rabbitmq ×1
scala ×1
spock ×1
spring-amqp ×1
uuid ×1
where-clause ×1