java-sdk
java-sdk copied to clipboard
Dapr pubsub subscriber issue
@Topic(name = "testingtopic", pubsubName = "messagebus") @PostMapping(path = "/testingtopic") public Mono<Void> handleMessage(@RequestBody(required = false) CloudEvent<String> cloudEvent) { return Mono.fromRunnable( () -> { try { System.out.println("Subscriber got: " + cloudEvent.getData()); System.out.println("Subscriber got: " + OBJECT_MAPPER.writeValueAsString(cloudEvent)); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }); getting an nullpointer exception on reading cloudEvent.getData(), On dapr sidecar logs,I can see {"app_id":"dpar-subscribe","instance":"dpar-subscribe-6d4cb75df7-5z7ph","level":"debug","msg":"user app did not subscribe to any topic","scope":"dapr.runtime","time":"2022-05-18T07:29:05.621296104Z","type":"log","ver":"1.7.2"}
@Venkat1188 can you share the entire logs?
Getting an nullpointer exception on reading cloudEvent.getData(), Error on dapr sidecar {"app_id":"dpar-subscribe","instance":"dpar-subscribe-67c7f44cc4-ndpm5","level":"error","msg":"non-retriable error returned from app while processing pub/sub event fd9d23c3-1f68-4222-8e9e-7960554017c3: \u003c!doctype html\u003e\u003chtml lang="en"\u003e\u003chead\u003e\u003ctitle\u003eHTTP Status 404 – Not Found\u003c/title\u003e\u003cstyle type="text/css"\u003ebody {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}\u003c/style\u003e\u003c/head\u003e\u003cbody\u003e\u003ch1\u003eHTTP Status 404 – Not Found\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e. status code returned: 404","scope":"dapr.runtime","time":"2022-05-18T11:14:47.153797787Z","type":"log","ver":"1.7.2"}
non-retriable error returned from app while processing pub/sub event fd9d23c3-1f68-4222-8e9e-7960554017c3: <!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1></body></html>. status code returned: 404
This happens if your app is not able to handle the cloud event, maybe it's unavailable, routing is not configured correctly, or the scopes have not been set properly. Can you share the code used to publish, along with pubsub component yaml files?
You can also check this quickstart - https://github.com/dapr/quickstarts/tree/master/pub_sub/java/sdk
public String publishMessage(String reqMessage) throws Exception {
String message = "This is message : " + reqMessage;
Map<String, String> metadata = new HashMap<>();
// metadata.put(Constants.KAFKA_PARTITION_KEY, eventAuditDTO.getRequestId());
metadata.put(Constants.KAFKA_PARTITION_KEY, UUID.randomUUID().toString());
metadata.put(Metadata.TTL_IN_SECONDS, MESSAGE_TTL_IN_SECONDS);
// Publishing messages
daprClient.publishEvent(PUBSUB_NAME, TOPIC_NAME, message, metadata)
// .block();
.subscribe(DaprPubSubSubscriber.getUniqueInstance());
System.out.println("Published message: " + message);
// This is an example, so for simplicity we are just exiting here.
// Normally a dapr app would be a web service and not exit main.
System.out.println("Done.");
return "SUCC";
}
Pubsub.yaml
apiVersion: dapr.io/v1alpha1 kind: Component metadata: name: messagebus namespace: default spec: type: pubsub.gcp.pubsub version: v1 metadata:
- name: type value: service_account
- name: projectId value:
- name: identityProjectId value:
- name: privateKeyId value:
- name: clientEmail value:
- name: clientId value:
- name: authUri value: https://accounts.google.com/o/oauth2/auth
- name: tokenUri value: https://oauth2.googleapis.com/token
- name: authProviderX509CertUrl value: https://www.googleapis.com/oauth2/v1/certs
- name: clientX509CertUrl value: https://www.googleapis.com
- name: privateKey value: "-----BEGIN PRIVATE KEY-----\n-----END PRIVATE KEY-----\n"
- name: disableEntityManagement value: "false"
- name: enableMessageOrdering value: "false"
- name: maxReconnectionAttempts # Optional value: 30
- name: connectionRecoveryInSec # Optional value: 2
Note, @Venkat1188 is getting the same error with the quick start https://github.com/dapr/quickstarts/tree/master/pub_sub/java/sdk. They are running Dapr on GKE.
Next action item is to update Java SDK from v1.4.0 to v1.5.0 based on https://github.com/dapr/java-sdk/issues/694
Still facing issues after update. @mukundansundar can you please move this to Java SDK?
Moved.
getting an nullpointer exception on reading cloudEvent.getData(), On dapr sidecar logs,I can see {"app_id":"dpar-subscribe","instance":"dpar-subscribe-6d4cb75df7-5z7ph","level":"debug","msg":"user app did not subscribe to any topic","scope":"dapr.runtime","time":"2022-05-18T07:29:05.621296104Z","type":"log","ver":"1.7.2"}
@Venkat1188 Have you configured the application to subscribe to any specific topic?
either using the either through the /subscribe API https://docs.dapr.io/reference/api/pubsub_api/#optional-application-user-code-routes
or through the Subscription CRD ?
Configured application to subscribe to a specific topic. This is the code, I am using for subscriptipn @Topic(name = "testingtopic", pubsubName = "messagebus") @PostMapping(path = "/testingtopic", consumes = MediaType.ALL_VALUE) public Mono<ResponseEntity> handleMessage( @RequestBody(required = false) CloudEvent<Order> cloudEvent) { return Mono.fromSupplier( () -> { try { log.info("Subscriber received: " + cloudEvent.getData().getMsg()); return ResponseEntity.ok("SUCCESS"); } catch (Exception e) { throw new RuntimeException(e); } }); } }