Skip to content
Snippets Groups Projects
Commit 264dd189 authored by Aman Verma's avatar Aman Verma
Browse files

using header directly

parent c25f8586
No related branches found
No related tags found
1 merge request!112Moving the while loop to iterate over storage records in azure code
Pipeline #30191 passed
...@@ -74,18 +74,16 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder { ...@@ -74,18 +74,16 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder {
@Override @Override
public void createWorkerTask(String payload, Long countdownMillis, DpsHeaders headers) { public void createWorkerTask(String payload, Long countdownMillis, DpsHeaders headers) {
headers.addCorrelationIdIfMissing(); headers.addCorrelationIdIfMissing();
createTask(payload, headers.getPartitionIdWithFallbackToAccountId(), headers.getCorrelationId()); createTask(payload, headers);
} }
@Override @Override
public void createReIndexTask(String payload, Long countdownMillis, DpsHeaders headers) { public void createReIndexTask(String payload, Long countdownMillis, DpsHeaders headers) {
headers.addCorrelationIdIfMissing(); headers.addCorrelationIdIfMissing();
String dataPartitionId = headers.getPartitionIdWithFallbackToAccountId(); publishAllRecordsToServiceBus(payload, headers);
String correlationId = headers.getCorrelationId();
publishAllRecordsToServiceBus(payload, dataPartitionId, correlationId);
} }
private Boolean publishAllRecordsToServiceBus(String payload, String dataPartitionId, String correlationId) { private void publishAllRecordsToServiceBus(String payload, DpsHeaders headers) {
// fetch all the remaining records // fetch all the remaining records
Gson gson = new Gson(); Gson gson = new Gson();
RecordReindexRequest recordReindexRequest = gson.fromJson(payload, RecordReindexRequest.class); RecordReindexRequest recordReindexRequest = gson.fromJson(payload, RecordReindexRequest.class);
...@@ -104,26 +102,24 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder { ...@@ -104,26 +102,24 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder {
.map(record -> RecordInfo.builder().id(record).kind(recordKind).op(OperationType.create.name()).build()).collect(Collectors.toList()); .map(record -> RecordInfo.builder().id(record).kind(recordKind).op(OperationType.create.name()).build()).collect(Collectors.toList());
Map<String, String> attributes = new HashMap<>(); Map<String, String> attributes = new HashMap<>();
attributes.put(DpsHeaders.ACCOUNT_ID, dataPartitionId); attributes.put(DpsHeaders.ACCOUNT_ID, headers.getPartitionIdWithFallbackToAccountId());
attributes.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); attributes.put(DpsHeaders.DATA_PARTITION_ID, headers.getPartitionIdWithFallbackToAccountId());
attributes.put(DpsHeaders.CORRELATION_ID, correlationId); attributes.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
RecordChangedMessages recordChangedMessages = RecordChangedMessages.builder().data(gson.toJson(records)).attributes(attributes).build(); RecordChangedMessages recordChangedMessages = RecordChangedMessages.builder().data(gson.toJson(records)).attributes(attributes).build();
String recordChangedMessagePayload = gson.toJson(recordChangedMessages); String recordChangedMessagePayload = gson.toJson(recordChangedMessages);
createTask(recordChangedMessagePayload, dataPartitionId, correlationId); createTask(recordChangedMessagePayload, headers);
} }
} while (!Strings.isNullOrEmpty(recordQueryResponse.getCursor()) && recordQueryResponse.getResults().size() == configurationProperties.getStorageRecordsBatchSize()); } while (!Strings.isNullOrEmpty(recordQueryResponse.getCursor()) && recordQueryResponse.getResults().size() == configurationProperties.getStorageRecordsBatchSize());
} catch (AppException e) { } catch (AppException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Unknown error", "An unknown error has occurred.", e); throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Unknown error", "An unknown error has occurred.", e);
} }
return true;
} }
private void createTask(String payload, String dataPartitionId, String correlationId) { private void createTask(String payload, DpsHeaders headers) {
Gson gson = new Gson(); Gson gson = new Gson();
RecordChangedMessages receivedPayload = gson.fromJson(payload, RecordChangedMessages.class); RecordChangedMessages receivedPayload = gson.fromJson(payload, RecordChangedMessages.class);
...@@ -131,9 +127,10 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder { ...@@ -131,9 +127,10 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder {
Map<String, Object> properties = new HashMap<>(); Map<String, Object> properties = new HashMap<>();
// properties // properties
properties.put(DpsHeaders.ACCOUNT_ID, dataPartitionId); properties.put(DpsHeaders.ACCOUNT_ID, headers.getPartitionIdWithFallbackToAccountId());
properties.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); properties.put(DpsHeaders.DATA_PARTITION_ID, headers.getPartitionIdWithFallbackToAccountId());
properties.put(DpsHeaders.CORRELATION_ID, dataPartitionId); headers.addCorrelationIdIfMissing();
properties.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
message.setProperties(properties); message.setProperties(properties);
// data // data
...@@ -142,9 +139,9 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder { ...@@ -142,9 +139,9 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder {
// add all to body {"message": {"data":[], "id":...}} // add all to body {"message": {"data":[], "id":...}}
JsonObject jo = new JsonObject(); JsonObject jo = new JsonObject();
jo.add("data", gson.toJsonTree(recordInfos)); jo.add("data", gson.toJsonTree(recordInfos));
jo.addProperty(DpsHeaders.ACCOUNT_ID, dataPartitionId); jo.addProperty(DpsHeaders.ACCOUNT_ID, headers.getPartitionIdWithFallbackToAccountId());
jo.addProperty(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); jo.addProperty(DpsHeaders.DATA_PARTITION_ID, headers.getPartitionIdWithFallbackToAccountId());
jo.addProperty(DpsHeaders.CORRELATION_ID, correlationId); jo.addProperty(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
JsonObject jomsg = new JsonObject(); JsonObject jomsg = new JsonObject();
jomsg.add("message", jo); jomsg.add("message", jo);
...@@ -152,13 +149,15 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder { ...@@ -152,13 +149,15 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder {
message.setContentType("application/json"); message.setContentType("application/json");
try { try {
logger.info("Indexer publishes message to Service Bus " + correlationId); logger.info("Indexer publishes message to Service Bus " + headers.getCorrelationId());
topicClientFactory.getClient(dataPartitionId, serviceBusTopic).send(message); topicClientFactory.getClient(headers.getPartitionId(), serviceBusTopic).send(message);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
} }
private List<RecordInfo> parseRecordsAsJSON(String inputPayload) { private List<RecordInfo> parseRecordsAsJSON(String inputPayload) {
Gson gson = new Gson(); Gson gson = new Gson();
Type type = new TypeToken<List<RecordInfo>>(){}.getType(); Type type = new TypeToken<List<RecordInfo>>(){}.getType();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment