spring-cloud-function icon indicating copy to clipboard operation
spring-cloud-function copied to clipboard

Supplier does not generate any http endpoint

Open akakunin opened this issue 6 years ago • 5 comments

Tested with 2.1.0.RELEASE

Simple test:

public class PingFunction implements Supplier<String> {
	private static Log logger = LogFactory.getLog(PingFunction.class);

        @Override
	public String get() {
		logger.info("Function Called");
		return "hello " + new Date();
	}
	
	public static void main(String[] args) {
		FunctionalSpringApplication.run(PingFunction.class, args);
	}
}

Does not generate http endpoint - then I'm trying to call with

# curl http://localhost:8080/

I've got HTTP 404. If I will change to (for example) implements Function<String,String> everything works fine (I can do the POST to http://localhost:8080/.

akakunin avatar May 20 '19 23:05 akakunin

Sorry just curious, have you ever tried GET http://localhost:8080/pingFunction? Assuming you are using web adapter, the documentation said it generates path with /{beanName}, and the default bean name should be pingFunction.

kleung avatar May 21 '19 08:05 kleung

Just tried http://localhost:8080/pingFunction - still 404. About Suppliers I only found in documentation GET /{supplier} - but it is not clear how the name is generated. In case I'm using implements Function<String,String> POST requests accepted by http://localhost:8080/ , so, I've accepted same for Supplier

akakunin avatar May 21 '19 10:05 akakunin

Please dont mind me, using web adapter... I am guessimg your use case is you need your application to be deployable on aws or azure as a cloud function but at the same time can fallback to paas as spring boot app... In that case, again, please dont mind, if time doesn't permit, I would suggest code an extra spring mvc rest controller and route the requests to your supplier, cons is obviously coding an extra controller, but pros is you can get away from your issue immediately while gaining full control of your rest api. Although you can use Message class to get the request headers, I think I still have no idea how to use path variable with web adapter.

kleung avatar May 21 '19 10:05 kleung

Also, if you have multiple function/consumer/supplier in the same project/jar, dont forget to use function.name properties or FUNCTION_NAME environment variable

kleung avatar May 21 '19 11:05 kleung

Hi Kleung! Thank you very much for your suggestions. Actually yes - I've switched to use web adapter and Supplier working as expected.

Only note - I think it is a bug - if implementation of Function<x,x> working fine with FunctionalSpringApplication, it is expected it should also work for Supplier. If not - it should be documented (somehow)

akakunin avatar May 21 '19 15:05 akakunin