Start Camunda instance from React - reactjs

I am trying to start using camunda.
So far I have created a spring boot service in order to build an api and later use it in my react application to start a process instance. This is my spring boot code :
package com.example.camundaNewTest;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.response.ProcessInstanceEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static io.camunda.zeebe.client.impl.util.VersionUtil.LOG;
#RestController
public class RestCalls {
#Qualifier("zeebeClientLifecycle")
#Autowired
private ZeebeClient client;
#CrossOrigin(origins = "http://localhost:3000")
#PostMapping("/start")
public void startInstance(#RequestHeader(value="var") String var) {
final ProcessInstanceEvent event =
client
.newCreateInstanceCommand()
.bpmnProcessId("demo")
.latestVersion()
.variables(Map.of("var", var))
.send()
.join();
LOG.info("Started instance for processDefinitionKey='{}', bpmnProcessId='{}', version='{}' with processInstanceKey='{}'",
event.getProcessDefinitionKey(), event.getBpmnProcessId(), event.getVersion(), event.getProcessInstanceKey());
}
}
This is working as expected. Now I want to do this call directly from my react app without a third service (spring). However, I can't find anything useful to achieve this. According to camunda documentation, it uses a grpc call to start the instance. So far, I have found some resources talking about react hooks (https://reactjsexample.com/a-react-hook-which-helps-you-to-deal-with-grpc-apis/) but I cannot make it work. Are there any ideas? Or similar situation that may hint the solution? Thank you!!

Related

web3.js to use with web development

I want to use web3.js together with my web page but the require function is not working for me. I have tried using browserify , importing instead of declaring as const but none worked, one problem solution lead to another problem. I tried to bundle these but web3 module has also some js inside which uses import statement so I am getting error to bundle them as well.
issue while using web3js with require
simple js code
issue while using web3js with import
simple js code
The import you wrote is wrong. Here are a few examples:
import {
Keypair,
AccountMeta,
Connection,
PublicKey,
Transaction,
TransactionInstruction,
sendAndConfirmTransaction,
} from "#solana/web3.js";
Or
import web3 = require('#solana/web3.js');

How to fix self is not defined when firebase messaging method called in react ssr app?

I am trying to use firebase massaging in my SSR app which is created using https://github.com/jaredpalmer/razzle with-react-router-3. I am already using firebase which works great including hosting. But started throwing an error when I started adding messaging in the app.
My entry point looks like,
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
import 'firebase/storage';
import 'firebase/firestore';
import 'firebase/messaging';
import FirebaseConfig from 'config/firebase-config.json';
if (!firebase.apps.length) {
firebase.initializeApp(FirebaseConfig);
}
const messaging = firebase.messaging();
I am getting the bellow error when I start the server with razzle start
/Users/subkundu/Desktop/Work/Projects/React/ownerstown/node_modules/#firebase/messaging/index.ts:75
if (self && 'ServiceWorkerGlobalScope' in self) {
^
ReferenceError: self is not defined
How do I fix it? Any lead will be amazing. Thanks. :)
I believe that you have to provide a check to see if the window is available.
let Messaging;
if (YOUR_CHECK_HERE) {
Messaging = firebase.messaging();
}
// Then you can use "Messaging"
I'm not familiar with razzle. Accessing the window varies depending on Server Side Rendering (SSR) frameworks. I got the idea from this post. When I ran into this problem with nuxt.js I was able to check for the window with this process.browser. Hope this helps!

Angular Firebase and AngularFireDatabase

In the angular firebase, I came across following two things:
import { AngularFireDatabase } from 'angularfire2/database';
import firebase from 'firebase';
If both can be used for interacting with the database, what is the difference between them?
The first line imports the AngularFire2 library.
The second line imports the Firebase JavaScript SDK, which is what AngularFire uses under the hood.

Annotation issue: #PrepareForTest cannot be resolved to a type

I am quite new to Selenium Webdriver with cucumber and is facing an issue while running the Junit test. I tried searching for the resolution to this issue on different forums but didn't get anything helpful, probably since I am new to this.
Below is the code where the problem is. All and any help is appreciated.
package firstCucumber;
import org.junit.runner.*;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.*;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.*;
import org.junit.Test;
#RunWith(Cucumber.class)
#PrepareForTest(TestRunner.class)
#CucumberOptions(
features = "Feature",
glue = {"stepDefiition"}
)
public class TestRunner {
}
It says #PrepareForTest cannot be resolved to a type at the line where # PrepareForTest is written
Add powermock-core-1.6.5.jar to the build path. I faced similar issue and it got resolved once after adding this jar

Spring Boot Custom ContextLoaderListener

I am trying to use RestEasy with Spring Boot. I need to configure it so it uses RestEasy's SpringContextLoaderListener instead of the Spring Boot default. I tried adding the listener in the config class but I get an error saying that a Context Loader Listener already exists.
Is there a way I can do this?
Rather than trying to use RESTEasy's SpringContextLoaderListener, you should be able to get this to work by dependency on org.jboss.resteasy:rest easy-spring and importing its springmvc-resteasy.xml configuration:
package sample.resteasy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
#Configuration
#ComponentScan
#EnableAutoConfiguration(exclude=WebMvcAutoConfiguration.class)
#ImportResource("classpath:springmvc-resteasy.xml")
public class SampleResteasyApplication {
public static void main(String[] args) {
SpringApplication.run(SampleResteasyApplication.class, args);
}
}
Note that WebMvcAutoConfiguration has been disabled. This is to work around a problem with RESTEasy's SpringBeanProcessor that causes a failure when it encounters a non-public #Bean method. WebMvcAutoConfiguration declares such a method so, to get RESTEasy to work, it has to be disabled.

Resources