1
1
package no .nav .vedtak .felles .integrasjon .kafka ;
2
2
3
- import java .util .Map ;
4
3
import java .util .Optional ;
5
4
import java .util .Properties ;
6
5
import java .util .UUID ;
13
12
import org .apache .kafka .common .config .SslConfigs ;
14
13
import org .apache .kafka .common .security .auth .SecurityProtocol ;
15
14
import org .apache .kafka .common .serialization .Deserializer ;
16
- import org .apache .kafka .common .serialization .Serde ;
17
- import org .apache .kafka .common .serialization .Serdes ;
18
- import org .apache .kafka .common .serialization .StringDeserializer ;
19
15
import org .apache .kafka .common .serialization .StringSerializer ;
20
- import org .apache .kafka .streams .StreamsConfig ;
21
- import org .apache .kafka .streams .errors .LogAndFailExceptionHandler ;
22
- import org .apache .kafka .streams .state .RocksDBConfigSetter ;
23
- import org .apache .kafka .streams .state .internals .BlockBasedTableConfigWithAccessibleCache ;
24
- import org .rocksdb .BloomFilter ;
25
- import org .rocksdb .LRUCache ;
26
- import org .rocksdb .Options ;
27
16
28
17
import no .nav .foreldrepenger .konfig .Environment ;
29
18
@@ -55,23 +44,18 @@ public static Properties forProducer() {
55
44
return props ;
56
45
}
57
46
58
- // Alle som konsumerer Json-meldinger
59
- public static Properties forConsumerStringValue (String groupId ) {
60
- return forConsumerGenericValue (groupId , new StringDeserializer (), new StringDeserializer (), Optional .empty ());
61
- }
62
-
63
- public static <K ,V > Properties forConsumerGenericValue (String groupId , Deserializer <K > valueKey , Deserializer <V > valueSerde , Optional <OffsetResetStrategy > offsetReset ) {
47
+ public static <K ,V > Properties forConsumerGenericValue (String groupId , Deserializer <K > keyDeserializer , Deserializer <V > valueDeserializer , OffsetResetStrategy offsetReset ) {
64
48
final Properties props = new Properties ();
65
49
66
50
props .put (CommonClientConfigs .GROUP_ID_CONFIG , groupId );
67
51
props .put (CommonClientConfigs .CLIENT_ID_CONFIG , generateClientId ());
68
52
props .put (CommonClientConfigs .BOOTSTRAP_SERVERS_CONFIG , getAivenConfig (AivenProperty .KAFKA_BROKERS ));
69
- offsetReset .ifPresent (or -> props .put (ConsumerConfig .AUTO_OFFSET_RESET_CONFIG , or .toString ()));
53
+ Optional . ofNullable ( offsetReset ) .ifPresent (or -> props .put (ConsumerConfig .AUTO_OFFSET_RESET_CONFIG , or .toString ()));
70
54
71
55
putSecurity (props );
72
56
73
- props .put (ConsumerConfig .KEY_DESERIALIZER_CLASS_CONFIG , valueKey .getClass ());
74
- props .put (ConsumerConfig .VALUE_DESERIALIZER_CLASS_CONFIG , valueSerde .getClass ());
57
+ props .put (ConsumerConfig .KEY_DESERIALIZER_CLASS_CONFIG , keyDeserializer .getClass ());
58
+ props .put (ConsumerConfig .VALUE_DESERIALIZER_CLASS_CONFIG , valueDeserializer .getClass ());
75
59
76
60
// Polling
77
61
props .put (ConsumerConfig .MAX_POLL_RECORDS_CONFIG , "100" ); // Unngå store Tx dersom alle prosesseres innen samme Tx. Default 500
@@ -80,33 +64,13 @@ public static <K,V> Properties forConsumerGenericValue(String groupId, Deseriali
80
64
return props ;
81
65
}
82
66
83
- // Alle som konsumerer Json-meldinger
84
- public static Properties forStreamsStringValue (String applicationId ) {
85
- return forStreamsGenericValue (applicationId , Serdes .String ());
86
- }
87
-
88
- public static <T > Properties forStreamsGenericValue (String applicationId , Serde <T > valueSerde ) {
89
- final Properties props = new Properties ();
90
-
91
- props .put (StreamsConfig .APPLICATION_ID_CONFIG , applicationId );
92
- props .put (StreamsConfig .CLIENT_ID_CONFIG , generateClientId ());
93
- props .put (StreamsConfig .BOOTSTRAP_SERVERS_CONFIG , getAivenConfig (AivenProperty .KAFKA_BROKERS ));
94
-
95
- putSecurity (props );
96
-
97
- props .put (StreamsConfig .DEFAULT_KEY_SERDE_CLASS_CONFIG , Serdes .String ().getClass ());
98
- props .put (StreamsConfig .DEFAULT_VALUE_SERDE_CLASS_CONFIG , valueSerde .getClass ());
99
- props .put (StreamsConfig .DEFAULT_DESERIALIZATION_EXCEPTION_HANDLER_CLASS_CONFIG , LogAndFailExceptionHandler .class );
100
-
101
- props .put (StreamsConfig .DEFAULT_DSL_STORE_CONFIG , StreamsConfig .IN_MEMORY );
102
- props .put (StreamsConfig .ROCKSDB_CONFIG_SETTER_CLASS_CONFIG , StreamsRocksReadOnly .class );
103
-
104
- // Polling
105
- props .put (ConsumerConfig .MAX_POLL_RECORDS_CONFIG , "200" );
106
- props .put (ConsumerConfig .MAX_POLL_INTERVAL_MS_CONFIG , "60000" );
67
+ /*
68
+ * Streams-config er fjernet. Ved evt re-innføring husk at det trends read+write til topic for å unngå log-spamming.
69
+ * - APPLICATION_ID_CONFIG = tisvarende verdi som brukes for GROUP_ID_CONFIG (men kan ikke ha både streams og consumer)
70
+ * - KEY+VALUE SERDE - typisk Serdes.String() + derserialization_exception = LogAndFailExceptionHandler
71
+ * - Bør se på rocksdb-setting (se i historikk)
72
+ */
107
73
108
- return props ;
109
- }
110
74
111
75
// Trengs kun for de som skal konsumere Avro. Ellers ikke
112
76
public static String getAvroSchemaRegistryURL () {
@@ -148,26 +112,4 @@ private static void putSecurity(Properties props) {
148
112
}
149
113
}
150
114
151
- public static class StreamsRocksReadOnly implements RocksDBConfigSetter {
152
-
153
- @ Override
154
- public void setConfig (final String storeName , final Options options , final Map <String , Object > configs ) {
155
-
156
- BlockBasedTableConfigWithAccessibleCache tableConfig = new BlockBasedTableConfigWithAccessibleCache ();
157
- tableConfig .setBlockCache (new LRUCache (1024 * 1024L ));
158
- tableConfig .setBlockSize (4096L );
159
- tableConfig .setFilterPolicy (new BloomFilter ());
160
- tableConfig .setCacheIndexAndFilterBlocks (true );
161
- options .setTableFormatConfig (tableConfig );
162
-
163
- options .setWriteBufferSize (512 * 1024L );
164
- options .setMaxWriteBufferNumber (2 );
165
- }
166
-
167
- @ Override
168
- public void close (final String storeName , final Options options ) {
169
- // NOOP
170
- }
171
- }
172
-
173
115
}
0 commit comments