I am using the Google Sample project to setup push notification on my app-engine backend. The following method is throwing an exception
private static void enqueuePushAlertToDevices(String alertMessage, String devicesAsJson) {
Queue notificationQueue = QueueFactory.getQueue("notification-delivery");
notificationQueue.add(TaskOptions.Builder.withMethod(TaskOptions.Method.PULL)
.param("alert", alertMessage)
.param("devices", devicesAsJson));
}
And the exception is
com.google.api.server.spi.SystemService invokeServiceMethod: The specified queue is unknown : notification-delivery
java.lang.IllegalStateException: The specified queue is unknown : notification-delivery
at com.google.appengine.api.taskqueue.QueueApiHelper.translateError(QueueApiHelper.java:104)
at com.google.appengine.api.taskqueue.QueueImpl$2.wrap(QueueImpl.java:552)
at com.google.appengine.api.taskqueue.QueueImpl$2.wrap(QueueImpl.java:521)
at com.google.appengine.api.utils.FutureWrapper.wrapAndCache(FutureWrapper.java:55)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:92)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88)
at com.google.appengine.api.taskqueue.QueueApiHelper.getInternal(QueueApiHelper.java:72)
at com.google.appengine.api.taskqueue.QueueImpl.add(QueueImpl.java:413)
....
Given that the project has been around, I imagine a number of developers have been using it. So where should I define the queue "notification-delivery"? I understand the problem: I am using a queue that is not yet defined. But it's not clear to me where I should define it. I haven't found an answer in the sample code as yet. Thanks.
You didn't look hard enough :). Actually it's not obvious. Just copy the queue.xml from the sample into your project. The path in the sample is
/Downloads/solutions-ios-push-notification-sample-backend-java-master/war/WEB-INF
Related
I have a Java azure function (runtime 3.2.0) where I try to send some custom telemetry. I use the following code
TelemetryConfiguration config = TelemetryConfiguration.getActive()
TelemetryClient telemetry = new TelemetryClient(config);
telemetry.trackEvent("Test Event");
telemetry.trackTrace("Test Trace", SeverityLevel.Warning);
telemetry.flush(); // Not sure it is needed
When I check config.getInstrumentationKey() is is the correct key for the Application Insights I want to show the custom telemetry. However, I never receive the custom event and trace in my Insights. Also config.isTrackingDisabled() i false and config.getChannel() seems to make sense.
All code examples I have found and in the official documentation as well it seems to be all the code I need. When I use the logger from the ExecutionContext logs appears in Application inside, so my function has access to it. So I suspect I have overlooked some small important fact or there is some configuration of my function that is not set correctly.
Can anybody help me get custom telemetry to work on my java function?
I used StartApplicationRequest to create a sample request to start the application as given below:
StartApplicationRequest request = StartApplicationRequest.builder()
.applicationId("test-app-name")
.build();
Then, I used the ReactorCloudFoundryClient to start the application as shown below:
cloudFoundryClient.applicationsV3().start(request);
But my test application test-app-name is not getting started. I'm using latest Java CF client version (v4.5.0 RELEASE), but not seeing a way around to start the application.
Quite surprisingly, the outdated version seems to be working with the below code:
cfstatus = cfClient.startApplication("test-app-name"); //start app
cfstatus = cfClient.stopApplication("test-app-name"); //stop app
cfstatus = cfClient.restartApplication("test-app-name"); //stop app
I want to do the same with latest CF client library, but I don't see any useful reference. I referred to test cases written at CloudFoundry official Github repo. I derived to the below code after checking out a lot of docs:
StartApplicationRequest request = StartApplicationRequest.builder()
.applicationId("test-app-name")
.build();
cloudFoundryClient.applicationsV3().start(request);
Note that cloudFoundryClient is ReactorCloudFoundryClient instance as the latest library doesn't support the client class used with outdated code. I would like to do all operations (start/stop/restart) with latest library. The above code isn't working.
A couple things here...
Using the reactor based client, your call to cloudFoundryClient.applicationsV3().start(request) returns a Mono<StartApplicationResponse>. That's not the actual response, it's the possibility of one. You need to do something to get the response. See here for more details.
If you would like similar behavior to the original cf-java-client, you can call .block() on the Mono<StartApplicationResponse> and it will wait and turn into a response.
Ex:
client.applicationsV3()
.start(StartApplicationRequest.builder()
.applicationId("test-app-name")
.build())
.block()
The second thing is that it's .applicationId not applicationName. You need to pass in an application guid, not the name. As it is, you're going to get a 404 saying the application doesn't exist. You can use the client to fetch the guid, or you can use CloudFoundryOperations instead (see #3).
The CloudFoundryOperations interface is a higher-level API. It's easier to use, in general, and supports things like starting an app based on the name instead of the guid.
Ex:
ops.applications()
.start(StartApplicationRequest.builder()
.name("test-app-name").build())
.block();
i am trying to trigger a java function each time my IoT Hub receives a batch of 64 messages (or whatever, the number is not important). I followed this guide to create the basic code, then i edited creating this function
public class Function {
#FunctionName("ProcessIotMessages")
public void processIotMessages(
#EventHubTrigger(name = "message",
eventHubName = "samples-workitems",
connection = "HUB-1544-DEV_events_IOTHUB") List<String> messages,
final ExecutionContext context) {...Function Logic...}
}
The connection parameter is the IoT Hub connection string in formatted as event hub compatible endpoint (e.g. Endpoint=sb://iothub-hostname-blablabla).
I package and deploy this code with maven plugins specified in the guide linked above. The deploys works fine, i can see mi function up and running with no errors from the portal, the HUB-1544-DEV_events_IOTHUB setting app is correctly created with the correct connection string.
The only strange thing i notice in the portal is in the trigger blade. As you can see, cardinality is One, while it should be set to many, since i did not specify the cardinality parameter in the function. The default one is many according to this guide. This makes me think that i not being able to pass the correct trigger syntax.
Anyway, the problem is that this function is not starting either from my local machine or the portal. Any suggestions? Thx
As #evilSnobu posted in the comments, the problem was the event hub name. Just go to Portal -> your IoT Hub -> Built-in endpoints and find all the information to configure the trigger in there.
I want to let my application to register for topic messaging, but each time I try to call Topic registration it is returning the error below
java.lang.IllegalArgumentException: Invalid topic name:
Using the method bellow
GcmPubSub.getInstance(context).subscribe(regToken, "/topics/testTopic", null);
I am using the tutorial on this link https://developers.google.com/cloud-messaging/topic-messaging. I will greatly appreciate your help on this error.
Please try this with the sample app. "/topics/testTopic" should be fine. As mentioned in the documentation, any topic name matching this regex should be fine: /topics/[a-zA-Z0-9-_.~%]+
For anyone running into this error: double check that you conform to the specification on the topic name: /topics/[a-zA-Z0-9-_.~%]+.
The original question actually does conform to the spec and I have no answer for why the error occurs. However another way to trigger the error is not conforming to the spec. In my case I mistakenly assumed path separator characters are allowed and used a topic like /topics/users/123 to mimic my REST API. The last slash is not allowed.
I have a strange behaviour in Google App Engine. I am developing with Eclipse and Java, specifically with Google Cloud Endpoints. I created a sample API with the following settings. Actually I was working with many others scopes but I decided to try with only one to track down the error.
#Api(
name = "adminmanagement",
version = "v1",
scopes = {AdminManagement.EMAIL_SCOPE},
clientIds = {AdminManagement.WEB_CLIENT_ID, AdminManagement.API_EXPLORER_CLIENT_ID}
)
public static final String EMAIL_SCOPE = "https://www.googleapis.com/auth/userinfo.email";
public static final String WEB_CLIENT_ID = "***.apps.googleusercontent.com";
public static final String API_EXPLORER_CLIENT_ID = com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID;
In the API Method as usual I check if the user object is null.
if (user == null) {
throw new OAuthRequestException("Unauthorised Access!");
}
This is pretty much straight forward and it always worked. However this time it does not. If I try to call the API method through the API Explorer I get the following error:
401 Unauthorized
And through the Eclipse Console I can see the following one:
INFO: getCurrentUser: AccessToken; scope not allowed
The SDK version is 1.9.1 but atm I have another application wich uses Drive API and works. I tryed deleting and creating a new Cloud Console, deleting and creating a new App Engine application but I always get this error. By the way, if I deploy the application on App Engine I get a 500 Internal Error with no specification and NOTHING shows up in the logs. Just the API call with no errors whatsover.
This is driving me crazy, what am I missing?
EDIT: The bug DOES NOT occur in version 1.8.9 and below...
The problem magically resolved itself, I haven't changed a thing, however I wasn't the only one with this problem so I supposed Google must have fixed something.