Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.35k stars 1.99k forks source link

Service or property not registered #465

Closed frank-montyne closed 7 years ago

frank-montyne commented 9 years ago

Hi,

I am using version 0.7.0 of the SDK and have the following problem: When I run my maven based application from within Eclipse I have no problems, I can connect to the Azure service bus and process messages.

Log: ... 2015-02-25 15:35:24.493 43 item(s) cached 2015-02-25 15:35:25.025 User xyz successfully connected to the Azure service bus cloud service 2015-02-25 15:35:25.294 Booting CAOGadgets (rmi) 2015-02-25 15:35:25.399 Creating registry for 2015-02-25 15:35:25.402 Binding rmi://10.164.14.118:7100/CAOGadgets to registry ...

However, when I run my packaged application from the command line I get the following exception:

Log: ... 2015-02-25 15:01:11.973 43 item(s) cached 2015-02-25 15:01:11.993 Connect to the Azure service bus cloud service as user bynubian failed, retrying java.lang.RuntimeException: Service or property not registered: com.microsoft.windowsazure.services.servicebus.ServiceBusContract interface com.microsoft.windowsazure.services.servicebus.ServiceBusContract at com.microsoft.windowsazure.core.DefaultBuilder.build(DefaultBuilder.java:197) ~[bynubian-services-caogadgets-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] at com.microsoft.windowsazure.Configuration.create(Configuration.java:113) ~[bynubian-services-caogadgets-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] at com.microsoft.windowsazure.services.servicebus.ServiceBusService.create(ServiceBusService.java:52) ~[bynubian-services-caogadgets-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] at com.bynubian.azure.servicebus.cloud.client.AzureServiceBusClient.connectToBroker(AzureServiceBusClient.java:122) ~[bynubian-services-caogadgets-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] at com.bynubian.services.caogadgets.server.CAOGadgetsServer.initialize(CAOGadgetsServer.java:83) [bynubian-services-caogadgets-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] at be.landc.framework.service.server.shared.Server.initialize(Server.java:98) [bynubian-services-caogadgets-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] at be.landc.framework.service.ipl.Boot.initialize(Boot.java:211) [bynubian-services-caogadgets-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] at be.landc.framework.service.ipl.Boot.(Boot.java:82) [bynubian-services-caogadgets-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] at be.landc.framework.service.ipl.Boot.main(Boot.java:320) [bynubian-services-caogadgets-0.0.1-SNAPSHOT-jar-with-dependencies.jar:na] ...

I have carefully checked if any dependencies were missing but fouynd none. Any help is greatly appreciated!

Frank Montyne www.byNubian.com

markcowl commented 9 years ago

@frank-montyne Thank you for the feedback. Assigning to the appropriate service team.

pizerg commented 9 years ago

Hi,

I also had this problem trying to use maven build + including dependencies, you will experience the same problem if you create a runnable jar "extracting" required libraries (from eclipse).

For me this problem was solved using the option "package" required libraries (from eclipse), so my guess is that when extracting required libraries (I think that's what maven assembly plugin does), some service reference is missing and it cannot be resolved during execution.

Regards,

Adrián Cañadas

carloscaverobarca commented 9 years ago

Hi,

See the workaround on https://github.com/Azure/azure-sdk-for-java/issues/466. There are problems with shaded jars, you only need to include org.apache.maven.plugins.shade.resource.ServicesResourceTransformer in the pom.xml to solve the issue. It worked for me.

Regards. Carlos.

veerubhai5c1 commented 9 years ago

Thank you, I faced same issue when I was running a executable jar that was built with gradle. I used https://github.com/johnrengelman/shadow to resolve it.

Regards, Veeresh

erickbp commented 9 years ago

@pizerg Hi, where is the options "package" required libraries (from eclipse)?

pizerg commented 9 years ago

@erickbp When you export a runnable jar, the second option.

boly38 commented 9 years ago

Hi all, I have a similar issue while trying to make a jar-with-dependencies of azure-servicebus.

I have tried to explain my sad workaround here (using 2 executions of maven assembly): http://stackoverflow.com/questions/27127107/error-accessing-azure-service-bus-from-storm-cluster

I don't know why exactly but the shadow workaround seems not working in my case... Hope this helps, and hope to get a clean azure dependency when this issue will be fixed ;)

dfaropennetwork commented 8 years ago

i 'ev the same problems with the azure-cloud plugin configuration for elasticsearch

veerubhai5c1 commented 8 years ago

In the gradle build script I have added this plugin apply plugin: 'com.github.johnrengelman.shadow'

Instead of jar task I used shadowJar task where I gave archive name and main class. The method mergeServiceFiles() merges the duplicate service file names. shadowJar { archiveName = "sample.jar" manifest { attributes 'Main-Class': ' com.test.asset.Test' } mergeServiceFiles() }

I hope this helps some one

Thanks, Veeresh

bviktor commented 8 years ago

+1 for Shade plugin.

<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
dobe commented 8 years ago

we have similar problems with 0.9.3 of the SDK. is there anyone working on this now @markcowl , or could you pls just explain why this is happening, so that we can find a workaround?

we plan to implement azure service discovery in https://github.com/crate/crate however it seems that this is a showstopper, since we do not deploy the azure jars with our product.

linehrr commented 7 years ago

for the sbt users who use the java libs(in my case I wrote the azure service bus connection module in java and my app is written in Scala importing this java module): I can pack java code into uber jar by using shade method mentioned above in maven. but when I tried to pack Scala app into a uber jar, this problem happened again. and since sbt does not have serviceTransformation plugin like maven, I got stuck for a while. here is my solution in sbt config to merge service registration properly:

assemblyMergeStrategy in assembly := {
    case x if Assembly.isConfigFile(x) =>
      MergeStrategy.concat
    case PathList(ps @ _*) if Assembly.isReadme(ps.last) || Assembly.isLicenseFile(ps.last) =>
      MergeStrategy.rename
    case PathList("META-INF", xs @ _*) =>
      (xs map {_.toLowerCase}) match {
        case ("manifest.mf" :: Nil) | ("index.list" :: Nil) | ("dependencies" :: Nil) =>
          MergeStrategy.discard
        case ps @ (x :: xs) if ps.last.endsWith(".sf") || ps.last.endsWith(".dsa") =>
          MergeStrategy.discard
        case "plexus" :: xs =>
          MergeStrategy.discard
        case "services" :: xs =>
          MergeStrategy.filterDistinctLines
        case ("spring.schemas" :: Nil) | ("spring.handlers" :: Nil) =>
          MergeStrategy.filterDistinctLines
        case _ => MergeStrategy.first
      }
    case _ => MergeStrategy.first
}

it handles the services and other META-INF properly. service registration now can get merged by using filterDistinctLines merge strategy.

PS. we really need to get this problem fixed in the Java API instead of all those hacks.

dionoid commented 7 years ago

Version 0.9.7 of the azure-servicebus artifact is still having these issues. The maven-shade-plugin fix doesn't work for me. Any suggestions?

peter-gerhard commented 7 years ago

+1 for Version 0.9.7

martinsawicki commented 7 years ago

the service bus client library is not in this repo anymore, so if this is still an issue, it should go there: https://github.com/azure/azure-service-bus-java