-
Notifications
You must be signed in to change notification settings - Fork 2
Legg til personer i kafkakø #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/bash | ||
|
|
||
| export SERVICEUSER_USERNAME=$(cat /secret/serviceuser/username) | ||
| export SERVICEUSER_PASSWORD=$(cat /secret/serviceuser/password) |
72 changes: 72 additions & 0 deletions
72
...lasjon/src/main/java/no/nav/registre/testnorge/originalpopulasjon/config/KafkaConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package no.nav.registre.testnorge.originalpopulasjon.config; | ||
|
|
||
| import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig; | ||
| import io.confluent.kafka.serializers.KafkaAvroSerializer; | ||
| import org.apache.kafka.clients.CommonClientConfigs; | ||
| import org.apache.kafka.clients.producer.ProducerConfig; | ||
| import org.apache.kafka.common.config.SaslConfigs; | ||
| import org.apache.kafka.common.config.SslConfigs; | ||
| import org.apache.kafka.common.serialization.LongSerializer; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.kafka.annotation.EnableKafka; | ||
| import org.springframework.kafka.core.DefaultKafkaProducerFactory; | ||
| import org.springframework.kafka.core.KafkaTemplate; | ||
| import org.springframework.kafka.core.ProducerFactory; | ||
|
|
||
| import java.io.File; | ||
| import java.net.InetSocketAddress; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import no.nav.registre.testnorge.libs.avro.person.Person; | ||
|
|
||
| @EnableKafka | ||
| @Configuration | ||
| public class KafkaConfig { | ||
|
|
||
| @Value("${kafka.bootstrapservers}") | ||
| public String bootstrapAddress; | ||
|
|
||
| @Value("${kafka.groupid}") | ||
| public String groupId; | ||
|
|
||
| @Value("${kafka.schemaregistryservers}") | ||
| public String schemaregistryServers; | ||
|
|
||
| @Value("${SERVICEUSER_USERNAME}") | ||
| public String username; | ||
|
|
||
| @Value("${SERVICEUSER_PASSWORD}") | ||
| public String password; | ||
|
|
||
| @Bean | ||
| public ProducerFactory<String, Person> producerFactory() { | ||
| InetSocketAddress inetSocketAddress = new InetSocketAddress(0); | ||
| Map<String, Object> props = new HashMap<>(); | ||
| props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress); | ||
| props.put(AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaregistryServers); | ||
| props.put(ProducerConfig.CLIENT_ID_CONFIG, groupId + inetSocketAddress.getHostString()); | ||
| props.put(ProducerConfig.ACKS_CONFIG, "1"); | ||
| props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, LongSerializer.class); | ||
| props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class); | ||
|
|
||
| props.put(SaslConfigs.SASL_MECHANISM, "PLAIN"); | ||
| props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_PLAINTEXT"); | ||
| props.put(SaslConfigs.SASL_JAAS_CONFIG, "org.apache.kafka.common.security.plain.PlainLoginModule required username=" + username + " password=" + password + ";"); | ||
|
|
||
| String navTruststorePath = System.getenv("NAV_TRUSTSTORE_PATH"); | ||
| if (navTruststorePath != null) { | ||
| props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_SSL"); | ||
| props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, new File(navTruststorePath).getAbsolutePath()); | ||
| props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, System.getenv("NAV_TRUSTSTORE_PASSWORD")); | ||
| } | ||
| return new DefaultKafkaProducerFactory<>(props); | ||
| } | ||
|
|
||
| @Bean | ||
| public KafkaTemplate<String, Person> kafkaTemplate() { | ||
| return new KafkaTemplate<>(producerFactory()); | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
...src/main/java/no/nav/registre/testnorge/originalpopulasjon/consumer/HendelseConsumer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package no.nav.registre.testnorge.originalpopulasjon.consumer; | ||
|
|
||
| import static org.reflections.Reflections.log; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.kafka.core.KafkaTemplate; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| import no.nav.registre.testnorge.libs.avro.person.Adresse; | ||
| import no.nav.registre.testnorge.libs.avro.person.Person; | ||
| import no.nav.registre.testnorge.libs.dto.person.v1.AdresseDTO; | ||
| import no.nav.registre.testnorge.libs.dto.person.v1.PersonDTO; | ||
|
|
||
| @Component | ||
| public class HendelseConsumer { | ||
|
|
||
| public HendelseConsumer(@Value("${kafka.topic}") String topic, KafkaTemplate<String, Person> kafkaTemplate) { | ||
| this.topic = topic; | ||
| this.kafkaTemplate = kafkaTemplate; | ||
| } | ||
|
|
||
| private final String topic; | ||
| private final KafkaTemplate<String, Person> kafkaTemplate; | ||
|
|
||
| public void registrertOpprettelseAvPerson(PersonDTO personDTO) { | ||
| AdresseDTO adresseDTO = personDTO.getAdresse(); | ||
| var adresse = adresseDTO == null | ||
| ? null | ||
| : Adresse.newBuilder() | ||
| .setGatenavn(adresseDTO.getGatenavn()) | ||
| .setPostnummer(adresseDTO.getPostnummer()) | ||
| .setPoststed(adresseDTO.getPoststed()) | ||
| .setKommunenummer(adresseDTO.getKommunenummer()) | ||
| .build(); | ||
|
|
||
| log.info("Sender person {} til kafkakø", personDTO.getIdent()); | ||
| kafkaTemplate.send( | ||
| topic, | ||
| Person.newBuilder() | ||
| .setIdent(personDTO.getIdent()) | ||
| .setFornavn(personDTO.getFornavn()) | ||
| .setMellomnavn(personDTO.getMellomnavn() == null ? "" : personDTO.getMellomnavn()) | ||
| .setEtternavn(personDTO.getEtternavn()) | ||
| .setFoedselsdato(personDTO.getFoedselsdato().toString()) | ||
| .setAdresse(adresse) | ||
| .setTags(new ArrayList<>(personDTO.getTags())) | ||
| .build() | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| SERVICEUSER_USERNAME: dummy | ||
| SERVICEUSER_PASSWORD: dummy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,10 @@ consumer: | |
| synt-person-api: | ||
| url: https://testnorge-synt-person-api.dev.adeo.no | ||
| client_secret: ${SYNT_PERSON_API_CLIENT_SECRET} | ||
| client_id: 9e22aba7-8c92-4f5e-8c0e-073e00c82bcf | ||
| client_id: 9e22aba7-8c92-4f5e-8c0e-073e00c82bcf | ||
|
|
||
| kafka: | ||
| bootstrapservers: b27apvl00045.preprod.local:8443,b27apvl00046.preprod.local:8443,b27apvl00047.preprod.local:8443 | ||
| schemaregistryservers: http://kafka-schema-registry.tpa.svc.nais.local:8081 | ||
| groupid: testnorge-hendelse-api-v1 #HVA GJØR VI MED DENNE? | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hva skal group-id være her?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Den iden skal du ikke trenge med mindre du motar noe fra kjøen. Tror jeg |
||
| topic: testnorge-opprett-person-v1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Foreløpig fiks før enum er på plass. Hvis vi lager en enum av tags, har vi både en enum og en database som holder oversikt. Smør på flesk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kansjke vi får se