1
- package com .kafkastream .events ;
1
+ package com .kafkastream .events . services ;
2
2
3
3
import com .kafkastream .constants .KafkaConstants ;
4
+ import com .kafkastream .dto .CustomerDto ;
4
5
import com .kafkastream .model .Customer ;
5
6
import com .kafkastream .model .CustomerOrder ;
6
7
import com .kafkastream .model .Greetings ;
24
25
import org .apache .kafka .streams .state .KeyValueStore ;
25
26
import org .apache .kafka .streams .state .StoreBuilder ;
26
27
import org .apache .kafka .streams .state .Stores ;
28
+ import org .springframework .http .HttpMethod ;
29
+ import org .springframework .http .ResponseEntity ;
27
30
import org .springframework .web .client .RestTemplate ;
28
31
29
32
import java .util .Collections ;
@@ -44,7 +47,7 @@ public class EventsListener
44
47
private static void setUp ()
45
48
{
46
49
properties = new Properties ();
47
- properties .put (StreamsConfig .APPLICATION_ID_CONFIG , KafkaConstants .APPLICATION_ID_CONFIG );
50
+ properties .put (StreamsConfig .APPLICATION_ID_CONFIG , KafkaConstants .APPLICATION_ID_CONFIG2 );
48
51
properties .put (StreamsConfig .BOOTSTRAP_SERVERS_CONFIG , KafkaConstants .BOOTSTRAP_SERVERS_CONFIG );
49
52
properties .put (StreamsConfig .APPLICATION_SERVER_CONFIG , KafkaConstants .APPLICATION_SERVER_CONFIG );
50
53
properties .put (StreamsConfig .COMMIT_INTERVAL_MS_CONFIG , KafkaConstants .COMMIT_INTERVAL_MS_CONFIG );
@@ -59,9 +62,12 @@ private static void setUp()
59
62
60
63
public static void main (String [] args )
61
64
{
65
+ //StateStoreService stateStoreService=new StateStoreService();
66
+
62
67
//Setup StreamsBuilder
63
68
setUp ();
64
69
70
+
65
71
SpecificAvroSerde <Customer > customerSerde = createSerde (KafkaConstants .SCHEMA_REGISTRY_URL );
66
72
SpecificAvroSerde <Order > orderSerde = createSerde (KafkaConstants .SCHEMA_REGISTRY_URL );
67
73
SpecificAvroSerde <Greetings > greetingsSerde = createSerde (KafkaConstants .SCHEMA_REGISTRY_URL );
@@ -90,7 +96,7 @@ public static void main(String[] args)
90
96
System .out .println ("orderKTable.value: " + order );
91
97
CustomerOrder customerOrder = new CustomerOrder ();
92
98
customerOrder .setCustomerId (order .getCustomerId ());
93
- Customer customer =getCustomerInformation (order .getCustomerId ());
99
+ CustomerDto customer =getCustomerInformation (order .getCustomerId ());
94
100
if (customer == null )
95
101
{
96
102
customerOrder .setFirstName ("" );
@@ -134,7 +140,6 @@ public static void main(String[] args)
134
140
e .printStackTrace ();
135
141
}
136
142
137
-
138
143
//Close Runtime
139
144
Runtime .getRuntime ().addShutdownHook (new Thread ("streams-shutdown-hook" )
140
145
{
@@ -148,10 +153,16 @@ public void run()
148
153
System .exit (0 );
149
154
}
150
155
151
- private static Customer getCustomerInformation (CharSequence customerId )
156
+ private static CustomerDto getCustomerInformation (CharSequence customerId )
152
157
{
153
158
RestTemplate restTemplate =new RestTemplate ();
154
- return restTemplate .getForObject ("http://localhost:8095/store/customer/" +customerId ,Customer .class );
159
+ if (customerId !=null )
160
+ {
161
+ ResponseEntity <CustomerDto > customerResponseEntity = restTemplate .exchange ("http://" +KafkaConstants .REST_PROXY_HOST +":" +KafkaConstants .REST_PROXY_PORT + "store/customer/" +customerId , HttpMethod .GET ,null , CustomerDto .class );
162
+ return customerResponseEntity .getBody ();
163
+
164
+ }
165
+ return null ;
155
166
}
156
167
157
168
0 commit comments