小编sen*_*vic的帖子

使用独立模式 Kafka-connect 将数据捕获从 Postgres SQL 更改为 kafka 主题

我一直在尝试使用以下命令 /bin connect-standalone.properties config/connect-standalone.properties postgres.sproperties 从 postgres sql 到 kafka 主题获取数据,但我面临着几个问题,这里是我的 postgres 的内容。属性文件:

name=cdc_demo
connector.class=io.debezium.connector.postgresql.PostgresConnector
tasks.max=1
plugin.name=decoderbufs
slot.name=debezium
slot.drop_on_stop=false
database.hostname=localhost
database.port=5432
database.user=postgres
database.password=XXXXX
database.dbname=snehildb
time.precision.mode=adaptive
database.sslmode=disable
database.server.name=localhost:5432/snehildb
table.whitelist=public.students
decimal.handling.mode=precise
topic.creation.enable=true`
Run Code Online (Sandbox Code Playgroud)

以下是 connect-standalone.properties 的内容:

# These are defaults. This file just demonstrates how to override some settings.
bootstrap.servers=localhost:9092

# The converters specify the format of data in Kafka and how to translate it into Connect data. Every 
Connect user will
# need to configure these based on the format they want …
Run Code Online (Sandbox Code Playgroud)

postgresql change-data-capture apache-kafka apache-kafka-connect debezium

7
推荐指数
1
解决办法
6631
查看次数

如何在Spring Boot中通过令牌自省端点实现令牌验证?

我们需要实现此端点,因为我们有许多需要验证令牌的微服务。

根据此链接,我们可以使用它返回一些用户详细信息以及验证令牌。

我浏览了Spring文档,但找不到任何东西。我们如何实现这一点,以便任何请求都自动调用自省端点。我在这里问这个问题是因为我想听听人们的经验和建议。

spring-security access-token oauth-2.0 spring-boot

6
推荐指数
1
解决办法
2409
查看次数

为什么 Spring boot Security 基本身份验证很慢?

我有一个 Spring boot 2.0.1 服务,我向其中添加了使用 BCrypt 进行哈希处理的基本身份验证。但这项服务在添加基本身份验证之前平均需要 400 毫秒,现在需要 1 秒以上。我正在使用用户详细信息服务,它在哈希映射中查找发送的用户名并返回用户详细信息。我尝试将 BCrypt 轮数减少到 4,但这并没有产生太大影响。

早些时候,我启用了无状态身份验证,后来将其禁用,但性能仍然很差。该服务托管在 Docker 容器中。

以下是我的安全配置。

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private UserDetailsService userDetailsService;

    @Autowired
    public SecurityConfig(UserDetailsServiceImpl service) {
        this.userDetailsService = service;
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        Map encoders = new HashMap<>();
        encoders.put(BCRYPT_ID, new BCryptPasswordEncoder(BCRYPT_ROUNDS));
        return new DelegatingPasswordEncoder(BCRYPT_ID,encoders);
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.cors()
            .and()
            .csrf().disable()
            .httpBasic();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

        auth.userDetailsService(userDetailsService)
            .passwordEncoder(passwordEncoder()); …
Run Code Online (Sandbox Code Playgroud)

java spring-security bcrypt basic-authentication spring-boot

6
推荐指数
3
解决办法
1万
查看次数

Spring Docker 容器无法访问 Postgres Docker 容器

我的 spring-boot 应用程序的 Dockerfile:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY target/media-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
Run Code Online (Sandbox Code Playgroud)

application.yml

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/media
    username: postgres
    password: postgres
    hikari:
      connectionTimeout: 30000
Run Code Online (Sandbox Code Playgroud)

这是docker-compose.yml

version: '3'
services:
  db:
    image: postgres
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: media
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres

  app:
    build:
      context: ./
      dockerfile: Dockerfile
    depends_on:
      - db
    ports:
      - "8080:8080"
Run Code Online (Sandbox Code Playgroud)

运行docker-compose up --build结果:

应用程序_1 | org.postgresql.util.PSQLException:连接到 0.0.0.0:5432 被拒绝。检查主机名和端口是否正确以及 postmaster 是否正在接受 TCP/IP 连接。应用_1

我的猜测是 spring 应用程序尝试在 postgres 准备好之前连接到 postgres,但我得到以下日志:

db_1 | …

postgresql docker spring-boot docker-compose

5
推荐指数
1
解决办法
3008
查看次数

Control.Monad.Reader.withReader 实际上是 Data.Functor.Contravariant.contramap 吗?

我正在深入研究 Haskell这本书,我注意到以下代码示例:

withReader :: (r' -> r) -> Reader r a -> Reader r' a
Run Code Online (Sandbox Code Playgroud)

这看起来像contramapControl.Monad.Reader和之间有什么关系Data.Functor.Contravariant

haskell functional-programming

5
推荐指数
1
解决办法
170
查看次数

Scala谓词组成

java谓词接口提供了or一种用于组合多个谓词的方法。例:

Predicate<Integer> p1;
Predicate<Integer> p2;

Predicate<Integer> p2 = p1.or(p2)
Run Code Online (Sandbox Code Playgroud)

由于scala没有Predicate接口,但Function1[A, Boolean]为此目的使用什么是编写此接口的最佳方法?最好不使用外部库。

我尝试避免以下情况:

val p1: (A => Boolean)
val p2: (A => Boolean)

val p3: (A => Boolean) = (a => p1(a) || p2(a))
Run Code Online (Sandbox Code Playgroud)

scala

4
推荐指数
1
解决办法
245
查看次数

Scala 成对遍历列表元素

下面的代码片段取自 GITHub Repo。在这段代码中,我们对接下来的两个数字求和。我的问题是在 doAction 函数必须在大括号末尾的 toList 中。为什么我们需要这个。如果我删除 toList ,那么它会导致问题。

def doAction(numbers:List[Int],action: (Int,Int) => Int):List[Int] =
{
  for(pair <- numbers.sliding(2)) yield {
    action(pair(0),pair(1))
  }
}.**toList**

var res = doAction(List(1,2,3,4,5,6,7,8),(a,b)=> a+b)
Run Code Online (Sandbox Code Playgroud)

2.如何使用map高阶函数重写相同的代码?

scala

3
推荐指数
1
解决办法
356
查看次数

Spring Boot中的同步事务

在Springboot中,我称之为服务的每个服务都会打开一个事务,当服务返回时它将关闭该连接,但就我而言,我需要创建一个将同步运行的方法(该方法仅在非同步方法中运行),并且他需要无论是否打开了一个事务,OPEN和CLOSE事务都是独立的,并且仅当THAT方法抛出错误时,该方法中的每个SQL操作才会回滚。如果调用它的方法抛出错误,他将不会回滚同步方法所做的任何事情。

因此,我尝试使用此示例:

@Service
public class MyService {
    @Autowired
    private MyRepository myRepository;

    public void methodNotSyncronized(String arg1, String arg2){
        logger.debug("init method no syncronied");
        MyObjct myObj = myRepository.findOne(1);

        methodSyncronized(arg2);

        myRepository.save(myObj);   //If I got some error here everything that methodSyncronized did should remaining
        logger.debug("finish method no syncronied");
    }

    @Transactional(isolation = Isolation.SERIALIZABLE, propagation = Propagation.REQUIRES_NEW)
    private synchronized  String methodSyncronized(String arg){
        logger.debug("init method  syncronied");
        //Here I will insert or delete something    
    }

}
Run Code Online (Sandbox Code Playgroud)

但是,当我调试此代码时,我得到了:

o.h.e.t.internal.TransactionImpl         : begin
                       myService         : init method no syncronied
                       myService         : init …
Run Code Online (Sandbox Code Playgroud)

java spring-data-jpa spring-boot

2
推荐指数
1
解决办法
334
查看次数

只运行一个包测试用例scala

我的包结构为:


    src ->  test -> scala -> notification

Run Code Online (Sandbox Code Playgroud)

内部通知我有两个包单元和集成。

单元包有单元测试,集成包有集成测试。我只想执行单元测试用例。我有没有办法只能通过 sbt 测试来做到这一点?

对于一节课,我知道可以这样做:我已经尝试过一节课,但不知道如何为 pacakge 做到这一点。

sbt "test:testOnly *LoginServiceSpec"

Run Code Online (Sandbox Code Playgroud)

scala sbt scalatest

2
推荐指数
1
解决办法
175
查看次数

Java:有关字符串连接和字符串中的变量替换的最佳实践

在Java中,有太多的方法来连接字符串和添加变量值。我应该如何选择一个(优点,缺点,最佳用例等)。

  • MessageFormat.format
  • 字符串格式
  • “字符串a” +“字符串b”
  • StringBuilder
  • 字符串缓冲区
  • String.concat
  • String.join()
  • Apache Commons的StringUtils
  • Google Guava的Joiner
  • ...

java string

1
推荐指数
1
解决办法
1860
查看次数

Akka后续讲述

后续调用发送的消息是否tell保证由参与者按照发送顺序进行处理?

例子:

actor ! message1
actor ! message2
Run Code Online (Sandbox Code Playgroud)

演员将message1始终message2按照发送的顺序看到。

java scala actor akka

0
推荐指数
1
解决办法
52
查看次数