Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Weather

...

Component

...

Available

...

as

...

of

...

Camel

...

2.12

...

The

...

weather:

...

component

...

is

...

used

...

for

...

polling

...

weather

...

information

...

from

...

Open

...

Weather

...

Map

...

-

...

a

...

site

...

that

...

provides

...

free

...

global

...

weather

...

and

...

forecast

...

information.

...

The

...

information

...

is

...

returned

...

as

...

a

...

json

...

String

...

object.

...

Camel

...

will

...

poll

...

for

...

updates

...

to

...

the

...

current

...

weather

...

and

...

forecasts

...

once

...

per

...

hour

...

by default. It can also be used to query the weather api based on the parameters defined on the endpoint which is used as producer.

Maven users will need to add the following dependency to their pom.xml for this component:

Code Block
xml
xml
 default.

Maven users will need to add the following dependency to their {{pom.xml}} for this component:
{code:xml}
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-weather</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

Code Block
{code}

h3. URI format

{code}
weather://<unused name>[?options]
{code}


h3. Options
{div:class=confluenceTableSmall}
|| Property || Default || Description ||
| {{location}} | {{null}} |  If null Camel will try and determine your current location using the geolocation of your ip address, else specify the city,country. For well known city names, Open Weather Map will determine the best fit, but multiple results may be returned. Hence specifying and country as well will return more accurate data. If you specify "current" as the location then the component will try to get the current latitude and longitude and use that to get the weather details. You can use lat and lon options instead of location. |
| {{lat}} | {{null}} | Latitude of location. You can use lat and lon options instead of location. |
| {{lon}} | {{null}} | Longitude of location. You can use lat and lon options instead of location. |
| {{period}} | {{null}} | If null, the current weather will be returned, else use values of 5, 7, 14 days. Only the numeric value for the forecast period is actually parsed, so spelling, capitalisation of the time period is up to you (its ignored) | 
| {{headerName}} | {{null}} | To store the weather result in this header instead of the message body. This is useable if you want to keep current message body as-is. |
| {{mode}} | {{JSON}} | The output format of the weather data. The possible values are {{HTML}}, {{JSON}} or {{XML}} | 
| {{units}} | {{METRIC}} | The units for temperature measurement. The possible values are {{IMPERIAL}} or {{METRIC}} | 
| {{consumer.delay}} | {{3600000}} | Delay in millis between each poll (default is 1 hour) |
| {{consumer.initialDelay}} | {{1000}} | Millis before polling starts. |
| {{consumer.userFixedDelay}} | {{false}} | If {{true}}, use fixed delay between polls, otherwise fixed rate is used. See [ScheduledExecutorService|http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html] in JDK for details. |
{div}

You can append query options to the URI in the following format, {{

REMARK

Since the 9th of October, an Api Key is required to access the openweather service. This key is passed as parameter to the URI definition of the weather endpoint using the appid param !

Options

Div
classconfluenceTableSmall

Property

Default

Description

appidnullCamel 2.16.1/2.15.5: APPID ID used to authenticate the user connected to the API Server. This key is required.

location

null

If null Camel will try and determine your current location using the geolocation of your ip address, else specify the city,country. For well known city names, Open Weather Map will determine the best fit, but multiple results may be returned. Hence specifying and country as well will return more accurate data. If you specify "current" as the location then the component will try to get the current latitude and longitude and use that to get the weather details. You can use lat and lon options instead of location.

lat

null

Latitude of location. You can use lat and lon options instead of location.

lon

null

Longitude of location. You can use lat and lon options instead of location.

period

null

If null, the current weather will be returned, else use values of 5, 7, 14 days. Only the numeric value for the forecast period is actually parsed, so spelling, capitalisation of the time period is up to you (its ignored)

headerName

null

To store the weather result in this header instead of the message body. This is useable if you want to keep current message body as-is.

mode

JSON

The output format of the weather data. The possible values are HTML, JSON or XML

units

METRIC

The units for temperature measurement. The possible values are IMPERIAL or METRIC

consumer.delay

3600000

Delay in millis between each poll (default is 1 hour)

consumer.initialDelay

1000

Millis before polling starts.

consumer.userFixedDelay

false

If true, use fixed delay between polls, otherwise fixed rate is used. See ScheduledExecutorService in JDK for details.

You can append query options to the URI in the following format, ?option=value&option=value&...

...

Exchange data format

Camel will deliver the body as a json formatted java.lang.String

...

(see

...

the

...

mode

...

option

...

above).

Message Headers

Div
classconfluenceTableSmall

Header

Description

CamelWeatherQuery

The original query URL sent to the Open Weather Map site

CamelWeatherLocation

Used by the producer to override the endpoint location and use the location from this header instead.

Samples

In this sample we find the 7 day weather forecast for Madrid, Spain:

Code Block



h3. Message Headers
{div:class=confluenceTableSmall}
|| Header || Description ||
| {{CamelWeatherQuery}} | The original query URL sent to the Open Weather Map site |
| {{CamelWeatherLocation}} | Used by the producer to override the endpoint location and use the location from this header instead. |
{div}

h3. Samples
In this sample we find the 7 day weather forecast for Madrid, Spain:

{code}
from("weather:foo?location=Madrid,Spain&period=7 days&appid=APIKEY").to("jms:queue:weather");
{code}

To

...

just

...

find

...

the

...

current

...

weather

...

for

...

your

...

current

...

location

...

you

...

can

...

use

...

this:

{
Code Block
}
from("weather:foo?appid=APIKEY").to("jms:queue:weather");
{code}

And

...

to

...

find

...

the

...

weather

...

using

...

the

...

producer

...

we

...

do:

{
Code Block
}
from("direct:start")
  .to("weather:foo?location=Madrid,Spain&appid=APIKEY");
{code}

And

...

we

...

can

...

send

...

in

...

a

...

message

...

with

...

a

...

header

...

to

...

get

...

the

...

weather

...

for

...

any

...

location

...

as

...

shown:

{
Code Block
}
  String json = template.requestBodyAndHeader("direct:start", "", "CamelWeatherLocation", "Paris,France&appid=APIKEY", String.class);
{code}

And

...

to

...

get

...

the

...

weather

...

at

...

the

...

current

...

location,

...

then:

{
Code Block
}
  String json = template.requestBodyAndHeader("direct:start", "", "CamelWeatherLocation", "current&appid=APIKEY", String.class);
{code}