Skip to content

Commit eb83811

Browse files
committed
optimize code of blobstorage function
1 parent a034b44 commit eb83811

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

gxazureserverless/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@
8888

8989
<dependency>
9090
<groupId>org.junit.jupiter</groupId>
91-
<artifactId>junit-jupiter</artifactId>
92-
<version>RELEASE</version>
91+
<artifactId>junit-jupiter-api</artifactId>
92+
<version>5.10.3</version>
9393
<scope>test</scope>
9494
</dependency>
95+
9596
</dependencies>
9697

9798
<build>
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.genexus.cloud.serverless.azure.handler;
2+
import com.genexus.cloud.serverless.Helper;
23
import com.genexus.cloud.serverless.model.*;
34

45
import com.microsoft.azure.functions.annotation.*;
@@ -9,6 +10,10 @@
910
import java.util.*;
1011

1112
public class AzureBlobStorageHandler extends AzureEventHandler{
13+
14+
EventMessages msgs = new EventMessages();
15+
String rawMessage ="";
16+
1217
public AzureBlobStorageHandler() throws Exception {
1318
super();
1419
}
@@ -17,28 +22,35 @@ public void run(
1722
@BindingName("name") String name,
1823
final ExecutionContext context
1924
) throws Exception {
25+
2026
context.getLogger().info("GeneXus Blob Storage trigger handler. Function processed: " + context.getFunctionName() + " Invocation Id: " + context.getInvocationId());
27+
setupServerlessMappings(context.getFunctionName());
2128

22-
EventMessages msgs = new EventMessages();
23-
EventMessage msg = new EventMessage();
24-
msg.setMessageId(context.getInvocationId());
25-
msg.setMessageSourceType(EventMessageSourceType.BLOB);
29+
switch (executor.getMethodSignatureIdx()) {
30+
case 0:
2631

27-
Instant nowUtc = Instant.now();
28-
msg.setMessageDate(Date.from(nowUtc));
29-
msg.setMessageData(Base64.getEncoder().encodeToString(content));
32+
EventMessage msg = new EventMessage();
33+
msg.setMessageId(context.getInvocationId());
34+
msg.setMessageSourceType(EventMessageSourceType.BLOB);
3035

31-
List<EventMessageProperty> msgAtts = msg.getMessageProperties();
36+
Instant nowUtc = Instant.now();
37+
msg.setMessageDate(Date.from(nowUtc));
38+
msg.setMessageData(Base64.getEncoder().encodeToString(content));
3239

33-
msgAtts.add(new EventMessageProperty("Id", context.getInvocationId()));
34-
msgAtts.add(new EventMessageProperty("name", name));
40+
List<EventMessageProperty> msgAtts = msg.getMessageProperties();
3541

36-
msgs.add(msg);
42+
msgAtts.add(new EventMessageProperty("Id", context.getInvocationId()));
43+
msgAtts.add(new EventMessageProperty("name", name));
3744

38-
setupServerlessMappings(context.getFunctionName());
45+
msgs.add(msg);
46+
break;
47+
case 1:
48+
case 2:
49+
rawMessage = Base64.getEncoder().encodeToString(content);
50+
}
3951

4052
try {
41-
EventMessageResponse response = dispatchEvent(msgs, Base64.getEncoder().encodeToString(content));
53+
EventMessageResponse response = dispatchEvent(msgs, rawMessage);
4254
if (response.hasFailed()) {
4355
logger.error(String.format("Messages were not handled. Error: %s", response.getErrorMessage()));
4456
throw new RuntimeException(response.getErrorMessage()); //Throw the exception so the runtime can Retry the operation.
@@ -47,6 +59,5 @@ public void run(
4759
logger.error("HandleRequest execution error", e);
4860
throw e; //Throw the exception so the runtime can Retry the operation.
4961
}
50-
5162
}
5263
}

0 commit comments

Comments
 (0)